-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ABW-2213] Manually Calculate Item Limit #729
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it to @umair-rdx to double-check.
|
||
FungibleResourcesSection(fungibles: viewStore.fungibleResourceIcons, itemLimit: limit) | ||
|
||
// FIXME: ViewThatFits is better, but it causes issues with @MainActor, which probably shouldn't be used in the first place |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which @MainActor
are you referring to @kugel3 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of our MainActors all over the place
// FIXME: Workaround to avoid ViewThatFits | ||
let limit = viewStore.state.itemLimit( | ||
iconSize: Constants.iconSize.rawValue, | ||
width: proxy.size.width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
geometry
is a more common name, but fine for now
func itemLimit(trying limits: [Int?], iconSize: CGFloat, width: CGFloat) -> Int? { | ||
for limit in limits { | ||
if usedWidth(itemLimit: limit, iconSize: iconSize) < width { | ||
return limit | ||
} | ||
} | ||
|
||
return 3 | ||
} | ||
|
||
func usedWidth(itemLimit: Int?, iconSize: CGFloat) -> CGFloat { | ||
let items = min(fungibleResourceIcons.count, itemLimit ?? .max) | ||
let showFungibleLabel = fungibleResourceIcons.count > items | ||
|
||
let hasItems = items > 0 | ||
let hasPoolUnits = poolUnitsCount > 0 | ||
let hasNFTs = nonFungibleResourcesCount > 0 | ||
let sections = (hasItems ? 1 : 0) + (hasPoolUnits ? 1 : 0) + (hasNFTs ? 1 : 0) | ||
|
||
var width: CGFloat = 0 | ||
|
||
if hasItems { | ||
let extraWidth = 2 * iconSize / 3 | ||
width += iconSize + CGFloat(items - 1) * extraWidth | ||
} | ||
if showFungibleLabel { | ||
width += iconSize | ||
} | ||
if hasPoolUnits { | ||
width += iconSize + .medium1 | ||
} | ||
if hasNFTs { | ||
width += iconSize + .medium1 | ||
} | ||
|
||
return width + max(CGFloat(sections - 1) * .small1, 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be private
or even nested in the itemLimit
method
@@ -241,6 +251,51 @@ extension AccountList.Row.View { | |||
} | |||
} | |||
|
|||
// FIXME: Workaround to avoid ViewThatFits | |||
extension AccountList.Row.ViewState { | |||
func itemLimit(iconSize: CGFloat, width: CGFloat) -> Int? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be a bit more explicit with naming here - it's about fingible resources, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the calculations looks right, let @umair-rdx help with testing
Yep, it's 1.0.0#13-Pre-Alpha @umair-rdx |
There is a subtle issue when we have more resources, but fine for now |
Jira ticket: ABW-2213
Description
Calculates the number of fungible icons to display manually, instead of using ViewThatFits, thereby avoiding data race warnings (and presumably potential issues)
Screenshot