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

switch Toggle will adjust sheet from large to medium #3

Closed
jagodki opened this issue Dec 16, 2021 · 4 comments
Closed

switch Toggle will adjust sheet from large to medium #3

jagodki opened this issue Dec 16, 2021 · 4 comments

Comments

@jagodki
Copy link

jagodki commented Dec 16, 2021

Hi,

first of all: thank you for this great project.
I discovered an issue I cannot explain me: I created a sheet with medium and large detent with the following code:

.shee(
isPresented: self.$sheet.isShowing,
presentationStyle: .formSheet(properties: SheetProperties(prefersEdgeAttachedInCompactHeight: true, prefersGrabberVisible: true, detents: [.medium(), .large()], largestUndimmedDetentIdentifier: .medium, prefersScrollingExpandsWhenScrolledToEdge: false)),
content: {self.sheetContent()}
)

I inserted some Toggles in a List to the sheet. If the sheet is pulled up to the large detent and I switch one toggle, the current detent of the sheet will immediately changed to medium. This does not happen with other controls like Buttons. Could this be a problem with Toggles because their toggle status has to be published and the whole view will be redrawn, i.e. the sheet will drawn in its start detent? Or could you imagine another reason for this behaviour?

Best regards,
Christoph

@edudnyk
Copy link
Owner

edudnyk commented Dec 16, 2021

Mind the parameter and documentation for it:

    /// The identifier of the selected detent. When `nil` or the identifier is not found in detents, the sheet is displayed at the smallest detent.
    /// Default: `nil`
    public var selectedDetentIdentifier: Binding<UISheetPresentationController.Detent.Identifier?>? = nil

Since you don't specify selectedDetentIdentifier binding when you create SheetProperties, and you don't provide the storage for newly chosen detent by the user, the default value is always nil, which causes sheet to always use smallest detent upon re-rendering of the content.

Create a @State private var selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? in a View where you present the sheet, and provide it as a parameter for SheetProperties:

.shee(
isPresented: self.$sheet.isShowing,
presentationStyle: .formSheet(properties: SheetProperties(prefersEdgeAttachedInCompactHeight: true, prefersGrabberVisible: true, detents: [.medium(), .large()], selectedDetentIdentifier: $selectedDetentIdentifier, largestUndimmedDetentIdentifier: .medium, prefersScrollingExpandsWhenScrolledToEdge: false)),
content: {self.sheetContent()}
)

@edudnyk
Copy link
Owner

edudnyk commented Dec 16, 2021

But I can agree that it's a good addition to the library to handle that automatically in case when there is 2 and more supported detents but no binding is provided. I'll add the fix for this.

@jagodki
Copy link
Author

jagodki commented Dec 17, 2021

As too often: had not reading the documentation carefully, sorry for that. Now I am using a state var for selectedDetentIdentifier and it works like a charm. Thank you for your advice 😀

I also tried the new version but did not notice any new behaviour, when I do not provide a state var for the selectedDetentIdentifier, i.e. it is nil.

@edudnyk
Copy link
Owner

edudnyk commented Dec 18, 2021

I haven't released the new version with the fix yet. Stay tuned 🙂

edudnyk added a commit that referenced this issue Dec 19, 2021
…ser's chosen detent is now never overwritten.
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

No branches or pull requests

2 participants