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

GT-2219 languages available offline #1940

Merged
merged 8 commits into from
Feb 13, 2024

Conversation

rachaelblue
Copy link
Collaborator

No description provided.

@rachaelblue rachaelblue marked this pull request as ready for review February 1, 2024 21:22
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 86 lines in your changes are missing coverage. Please review.

Comparison is base (6f3e76b) 20.91% compared to head (b9d4e77) 20.88%.
Report is 10 commits behind head on develop.

Files Patch % Lines
...terface/GetDownloadedLanguagesListRepository.swift 0.00% 29 Missing ⚠️
...bleOffline/ToolLanguagesAvailableOfflineView.swift 0.00% 19 Missing ⚠️
.../Domain/UseCases/ViewLanguageSettingsUseCase.swift 0.00% 9 Missing ⚠️
...ews/ToolLanguageAvailableOfflineLanguageView.swift 0.00% 9 Missing ⚠️
...pository/Cache/RealmDownloadedLanguagesCache.swift 0.00% 6 Missing ⚠️
...iner/AppLanguageFeatureDataLayerDependencies.swift 0.00% 6 Missing ⚠️
...agesRepository/DownloadedLanguagesRepository.swift 0.00% 2 Missing ⚠️
...er/AppLanguageFeatureDomainLayerDependencies.swift 0.00% 2 Missing ⚠️
...tities/DownloadedLanguageListItemDomainModel.swift 0.00% 2 Missing ⚠️
...n/LanguageSettings/LanguageSettingsViewModel.swift 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1940      +/-   ##
===========================================
- Coverage    20.91%   20.88%   -0.03%     
===========================================
  Files         1008     1010       +2     
  Lines        31576    31619      +43     
===========================================
  Hits          6604     6604              
- Misses       24972    25015      +43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@levieggertcru levieggertcru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rachaelblue this is looking good! This PR was nice and simple to review.
Although the interface and repository takes some additional time to setup, it really does help separate logic that would be bloating the ViewModel.

Just a couple change requests and also shared some thoughts in ToolLanguagesAvailableOfflineView. Let me know your thoughts on those UI comments I had left.

ToolLanguageAvailableOfflineLanguageView()
ScrollView(.vertical, showsIndicators: true) {

VStack(alignment: .leading, spacing: 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops I should've had LazyVStack here in the dummy setup.

ToolLanguageAvailableOfflineLanguageView()
let buttonHeight: CGFloat = 50
let spaceBelowScrollView: CGFloat = 25
let scrollViewMaxHeight: CGFloat = scrollViewGeometry.size.height - buttonHeight - spaceBelowScrollView
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too crazy about this calculation here for the scrollViewMaxHeight. I would prefer the layout to simply adapt without having to do any calculations.
Another reason is if we modify this view to add additional UI below the scrollView then we have to update scrollViewMaxHeight which may not be known to do. More bug prone that way.

Was their an issue with original layout structure. I think the way it was before the ScrollView would still wrap the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem before was that the scrollView took up the maximum space and always forced the blue button to the bottom of the screen, even if there were only a few rows in the scrollView:

Whereas Figma has the button directly beneath the last row:
Screenshot 2024-02-02 at 3 56 18 PM

I was trying to figure out a way to do this without calculations, but just doing .fixedSize(horizontal: false, vertical: true) without also setting the maxHeight ends up pushing the blue button off the screen if there's too many rows. I can play with this some more and see if there's a better solution

Copy link
Collaborator

@levieggertcru levieggertcru Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rachaelblue I see what you're saying now about the button sticking to the bottom of the screen originally.

It would be nice to have the scrollview wrap it's content, but then you're right, it seems that would introduce the possibility of the button getting pushed off screen.

It would be nice if there were some solution where that height didn't have to be calculated by explicitly telling it which spacings and element heights needed removing. It does open the possibility of creating a UI bug in the future. If you find yourself spending too much time here then I'd say create a ticket for it and it can be re-investigated later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried a few different things here, but none quite had the desired result. It seems that SwiftUI doesn't let you make the ScrollView shrink to fit its content while also ensuring the view stays within the safeArea, unless you explicitly set a maxHeight to keep it within the safe area. Went ahead and made a ticket: https://jira.cru.org/browse/GT-2287

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rachaelblue thanks for checking into that some more. You're right we would need some way to tell it not to expand beyond the safe area. Thank you for making the ticket too, maybe something will be available in the future to allow for that behavior.

let spaceBelowScrollView: CGFloat = 25
let scrollViewMaxHeight: CGFloat = scrollViewGeometry.size.height - buttonHeight - spaceBelowScrollView

VStack(alignment: .leading, spacing: spaceBelowScrollView) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think VStack and HStack spacing you have to be careful sometimes in how it's used. To me it makes more sense in lists of repeating elements or where a ForEach is used.

In this particular case it still works since the VStack contains only a ScrollView and Button, however there is the potential of this breaking if we later update this UI to include some additional elements between the Button and ScrollView. We'd most likely want variable spacing between those elements.

I think here it would be more preferred to have this spacing applied either as a bottom padding to the ScrollView or top padding to the Button.

Comment on lines +34 to +37
if completedDownloadsOnly {
realmDownloadedLanguages = realmDownloadedLanguages
.where { $0.downloadComplete }
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is what you meant or not 😄 but it's a little better since it returns the same Result type. Is there a different way to do it that I'm missing?

Originally I was doing the condition inside the filter, like

var downloadedLanguages = realmDatabase.openRealm()
            .objects(RealmDownloadedLanguage.self)
            .filter { completedDownloadsOnly ? $0.downloadComplete : true }
            .map { DownloadedLanguageDataModel(realmDownloadedLanguage: $0) }

But thought there's no reason to perform the filter when completedDownloadsOnly = false just because it looks cleaner. I guess .where would also work in that ^ scenario. Seems like the only difference between .filter and .where is the return type. And maybe it's more readable to use the word "where" in cases like this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rachaelblue oh wow my eyes and my brain were seeing something different this morning.

For some reason I thought your else statement was filtering on objects where downloadComplete was false. But, if that were the case you could still use .filter and check if downloadComplete was equal to completedDownloadsOnly without the need for the conditional.

Sorry for the confusion there! I was seeing something different and my brain was thinking something different.

@rachaelblue rachaelblue merged commit 9e80df8 into develop Feb 13, 2024
3 checks passed
@rachaelblue rachaelblue deleted the GT-2219-Languages-Available-Offline branch February 13, 2024 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants