11import { useMemo , useState } from 'react' ;
2- import { StyleSheet , type ViewProps , type ViewStyle } from 'react-native' ;
2+ import {
3+ Platform ,
4+ StyleSheet ,
5+ type ViewProps ,
6+ type ViewStyle ,
7+ } from 'react-native' ;
38import { runOnJS , useAnimatedReaction } from 'react-native-reanimated' ;
49import { useBottomSheetInternal } from './useBottomSheetInternal' ;
510
@@ -9,16 +14,18 @@ export function useBottomSheetContentContainerStyle(
914) {
1015 const [ footerHeight , setFooterHeight ] = useState ( 0 ) ;
1116 //#region hooks
12- const { animatedFooterHeight } = useBottomSheetInternal ( ) ;
17+ const { animatedFooterHeight, animatedContentHeight } =
18+ useBottomSheetInternal ( ) ;
1319 //#endregion
1420
1521 //#region styles
1622 const flattenStyle = useMemo < ViewStyle > ( ( ) => {
1723 return ! _style
1824 ? { }
1925 : Array . isArray ( _style )
20- ? StyleSheet . compose ( ..._style )
21- : _style ;
26+ ? // @ts -ignore
27+ ( StyleSheet . compose ( ..._style ) as ViewStyle )
28+ : ( _style as ViewStyle ) ;
2229 } , [ _style ] ) ;
2330 const style = useMemo < ViewProps [ 'style' ] > ( ( ) => {
2431 if ( ! enableFooterMarginAdjustment ) {
@@ -28,7 +35,16 @@ export function useBottomSheetContentContainerStyle(
2835 let currentBottomPadding = 0 ;
2936 if ( flattenStyle && typeof flattenStyle === 'object' ) {
3037 const { paddingBottom, padding, paddingVertical } = flattenStyle ;
31- currentBottomPadding = paddingBottom ?? paddingVertical ?? padding ?? 0 ;
38+ if ( paddingBottom !== undefined && typeof paddingBottom === 'number' ) {
39+ currentBottomPadding = paddingBottom ;
40+ } else if (
41+ paddingVertical !== undefined &&
42+ typeof paddingVertical === 'number'
43+ ) {
44+ currentBottomPadding = paddingVertical ;
45+ } else if ( padding !== undefined && typeof padding === 'number' ) {
46+ currentBottomPadding = padding ;
47+ }
3248 }
3349
3450 return [
@@ -44,15 +60,27 @@ export function useBottomSheetContentContainerStyle(
4460 //#region effects
4561 useAnimatedReaction (
4662 ( ) => animatedFooterHeight . get ( ) ,
47- result => {
63+ ( result , previousFooterHeight ) => {
4864 if ( ! enableFooterMarginAdjustment ) {
4965 return ;
5066 }
5167 runOnJS ( setFooterHeight ) ( result ) ;
68+
69+ if ( Platform . OS === 'web' ) {
70+ /**
71+ * a reaction that will append the footer height to the content
72+ * height if margin adjustment is true.
73+ *
74+ * This is needed due to the web layout the footer after the content.
75+ */
76+ if ( result && ! previousFooterHeight ) {
77+ const contentHeight = animatedContentHeight . get ( ) ;
78+ animatedContentHeight . set ( contentHeight + result ) ;
79+ }
80+ }
5281 } ,
53- [ animatedFooterHeight ]
82+ [ animatedFooterHeight , animatedContentHeight , enableFooterMarginAdjustment ]
5483 ) ;
5584 //#endregion
56-
5785 return style ;
5886}
0 commit comments