-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/navigation update #47
base: feature/mac-support
Are you sure you want to change the base?
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.
Good work! Still, check the comments I've added.
#if os(macOS) | ||
ToolTableItem.navigation( | ||
NavigationToolItem( | ||
title: key, | ||
didSelect: { | ||
UserDefaultsToolDetailView( | ||
viewModel: UserDefaultsToolDetailViewModel( | ||
value: String(describing: value), | ||
title: key, | ||
userDefaults: userDefaults, | ||
didDeleteProperty: { [unowned self] in sections = createSectionItems(with: userDefaults) } | ||
), | ||
selection: $0 | ||
) | ||
} | ||
) | ||
) | ||
#else | ||
ToolTableItem.navigation( | ||
NavigationToolItem( | ||
title: key, | ||
didSelect: { | ||
UserDefaultsToolDetailView( | ||
viewModel: UserDefaultsToolDetailViewModel( | ||
value: String(describing: value), | ||
title: key, | ||
userDefaults: userDefaults, | ||
didDeleteProperty: nil // onAppear will update the screen on iOS | ||
) | ||
) | ||
} | ||
) | ||
) | ||
#endif |
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 would prefer moving didSelect
into separate method, or just defining didDeleteProperty
as a standalone variable and init the variable based on if-else
.
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.
The difference between didSelect closures is messing up this one. The macOS one has a value provided in it which is then sent as the selection parameter, and the iOS one doesn't. Nothing comes to mind on how to handle this elegantly. Maybe you might think of something
#if os(macOS) | ||
selection = nil | ||
#else | ||
presentationMode.wrappedValue.dismiss() // on macOS dismisses the whole window which isn't desired |
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've seen this used multiple times; can we instead make an extension that will handle this case by calling it as a one liner on a calling side and define inner logic in the extension?
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.
To extract this into a protocol or something we would still have to have if/else since the selection is hidden behind an if macos, and we would have to provide it somehow. It's called twice in the codebase, so for now, maybe we can leave it as is since macOS might be upped to version 13 so we can use NavigationStack
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> | ||
@ObservedObject var viewModel: UserDefaultsToolDetailViewModel | ||
#if os(macOS) | ||
@Binding var selection: String? |
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 we move this to the viewModel
?
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.
Since it's a view specific binding, I feel like we should keep it here
let title: String | ||
let onValueChanged: (Bool) -> Void | ||
let getter: () -> Bool |
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 issue is fixed with adding a getter
which is called on onAppear
? Does item.loadStoredValue()
not provide the correct value, and if not, in which cases?
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.
The issue was if we remove a value from the UserDefaultsTool which was in preferences, when we go back to the preferences it would keep the previous value since it was only instantiated once. This way we would check the value every time we enter the screen since it might have changed
Summary
I have update the current state of the UserDefaults tool to match the changes done in the preferences tab, and vice versa. Also, I have updated the macOS navigation so that the users can now pop the view in the NavigationSplitView that's used on macOS instead of being open for no reason.
Changes
The navigation changes are mostly done only for macOS since we needed to provide the selection binding from the SentinelListView.
The preference tab changes only added an onAppear to update the value if needed.
The UserDefaults changes are updating the view onAppear as well.
Type
Additional information
Description
Everything was mentioned in the changes section
Sentinel.updates.mov
Checklist
Additional notes