Skip to content
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

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

kugel3
Copy link
Contributor

@kugel3 kugel3 commented Sep 7, 2023

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

image

Copy link
Contributor

@maciek-rdx maciek-rdx left a 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
Copy link
Contributor

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 ?

Copy link
Contributor

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
Copy link
Contributor

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

Comment on lines +260 to +296
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)
}
Copy link
Contributor

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? {
Copy link
Contributor

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?

@maciek-rdx maciek-rdx added the DO NOT MERGE Merging is blocked or prohibited due to missing specs or other higher priority PRs label Sep 7, 2023
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a 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

@maciek-rdx
Copy link
Contributor

Yep, it's 1.0.0#13-Pre-Alpha @umair-rdx

@maciek-rdx maciek-rdx merged commit 01ed209 into main Sep 7, 2023
6 checks passed
@maciek-rdx maciek-rdx deleted the ABW-2213_MainActor-issue-on-account-cards branch September 7, 2023 11:34
@maciek-rdx
Copy link
Contributor

maciek-rdx commented Sep 7, 2023

There is a subtle issue when we have more resources, but fine for now

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE Merging is blocked or prohibited due to missing specs or other higher priority PRs
Development

Successfully merging this pull request may close these issues.

3 participants