-
-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Android): cleanup sheet behavior configuration (#2420)
## Description I plant to extract most of the form sheet API related code out of `ScreenStackFragment`, so that it is not polluted that much and more readable. Having experienced the #2045, where big changes were rolled out at once, now I want to do it in couple of separate PRs. This one simplifies sheet behaviour configuration logic in ScreenStackFragment by implementing series of helper extension functions on BottomSheetBehavior. ## Test code and steps to reproduce Test1649 ## Checklist - [ ] Included code example that can be used to test this change - [ ] Updated TS types - [ ] Updated documentation: <!-- For adding new props to native-stack --> - [ ] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx - [ ] Ensured that CI passes
- Loading branch information
Showing
3 changed files
with
103 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetBehaviorExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.swmansion.rnscreens.bottomsheet | ||
|
||
import android.view.View | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
|
||
internal fun <T : View> BottomSheetBehavior<T>.useSingleDetent(height: Int? = null, forceExpandedState: Boolean = true): BottomSheetBehavior<T> { | ||
this.skipCollapsed = true | ||
this.isFitToContents = true | ||
if (forceExpandedState) { | ||
this.state = BottomSheetBehavior.STATE_EXPANDED | ||
} | ||
height?.let { maxHeight = height } | ||
return this | ||
} | ||
|
||
internal fun <T : View> BottomSheetBehavior<T>.useTwoDetents( | ||
@BottomSheetBehavior.StableState state: Int? = null, | ||
firstHeight: Int? = null, | ||
secondHeight: Int? = null | ||
): BottomSheetBehavior<T> { | ||
skipCollapsed = false | ||
isFitToContents = true | ||
state?.let { this.state = state } | ||
firstHeight?.let { peekHeight = firstHeight } | ||
secondHeight?.let { maxHeight = secondHeight } | ||
return this | ||
} | ||
|
||
internal fun <T : View> BottomSheetBehavior<T>.useThreeDetents( | ||
@BottomSheetBehavior.StableState state: Int? = null, | ||
firstHeight: Int? = null, | ||
halfExpandedRatio: Float? = null, | ||
expandedOffsetFromTop: Int? = null | ||
): BottomSheetBehavior<T> { | ||
skipCollapsed = false | ||
isFitToContents = false | ||
state?.let { this.state = state } | ||
firstHeight?.let { this.peekHeight = firstHeight } | ||
halfExpandedRatio?.let { this.halfExpandedRatio = halfExpandedRatio } | ||
expandedOffsetFromTop?.let { this.expandedOffset = expandedOffsetFromTop } | ||
return this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters