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

Specify Positions Sheet Can Move To #4

Closed
dbarsamian opened this issue Mar 5, 2021 · 2 comments
Closed

Specify Positions Sheet Can Move To #4

dbarsamian opened this issue Mar 5, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@dbarsamian
Copy link

Description

The option to specify the available positions the bottom sheet can move to should be available.

Motivation

There are cases where the middle position state is not necessary to have and even hinders the user experience. Furthermore, dynamic control over the available states would allow for some complex UI design currently not possible, such as allowing a sheet to react to the content inside by changing it's allowed states.

Proposed Solution

Ideally, this would be made available by offering an optional parameter in the constructor to pass in a binding of an array containing all of the allowed position states. This would allow flexibility for static construction of a bottom sheet as well as the dynamic changing of the allowed states.

Example

A static example:

.bottomSheet(bottomSheetPosition: $bottomSheetPosition, availablePositions: [.bottom, .top], resizeable: true, mainContent: { 
    // Content 
}

A dynamic example:

@Binding var availablePositions: [BottomSheetPosition] = [.bottom, .top]
.bottomSheet(bottomSheetPosition: $bottomSheetPosition, availablePositions: $availablePositions, resizeable: true, mainContent: {
    // Content
}
@lucaszischka
Copy link
Owner

Yes i think this is an awesome idea and I already thought about doing it.

But I would take it a step further, but im sot sure what would me the best way to implement it, that's why I wasn't working in it jet.

Description

Same idea, but you also have the option to add more states and set the position for any state.

Proposed Solution

Maybe we can archive this by making BottomSheetPosition a class or struct and then subclassing BottomSheetPosition. Or we accept a enum of type CGFloat in the constructor.

Also we would need the user to provide us with the functions for the Drag Indicator (switchPositionIndicator) and the setting of the states (switchPositionUp and switchPositionDown).

Example

SUBCLASSING

struct CustomBottomSheetPosition: BottomSheetPosition {

    let cases: [String: Int] = [top : 1, middle : 0.6]

    func switchPositionIndicator() {
        //
    }

    func switchPositionUp() {
        //
    }

    func switchPositionDown() {
        //
    }
}

ENUM

public enum BottomSheetPosition: CGFloat {
    case top = 0.1, topMiddle = 0.6, middle = 0.4, hidden = 0
}

Problems

SUBCLASSING

Im not sure what data type to use for the cases and how and where to pass in the subclass. This is still a very theoretical concept, but I think it is way better than just using predefined states. I also think that I would provide a couple of predefined BottomSheetPosition for the most common use cases. (2 States, 3 States)

ENUM

With an enum Im not sure how to implement switchPositionIndicator etc.

@lucaszischka lucaszischka added the enhancement New feature or request label Mar 5, 2021
lucaszischka added a commit that referenced this issue Mar 8, 2021
@lucaszischka
Copy link
Owner

@dbarsamian Hey please have a look at #5 and tell me your thoughts about this solution and if you have any ideas to improve it.

@lucaszischka lucaszischka self-assigned this Mar 8, 2021
lucaszischka added a commit that referenced this issue Mar 8, 2021
Plenty README.md updates.
Fixed Dependencies.
Custom States feature.
Extended SearchBar support.
@lucaszischka lucaszischka removed their assignment Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants