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

fix: padding in scrollview bottomsheet #172

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/components/common/CustomView.res
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
open ReactNative
open Style
type modalPosition = [#center | #top | #bottom]

@react.component
let make = (
~onDismiss=() => (),
~children,
~closeOnClickOutSide=true,
~modalPosition: modalPosition=#bottom,
~modalPosition=#bottom,
~bottomModalWidth=100.->pct,
(),
) => {
let (viewPortContants, _) = React.useContext(ViewportContext.viewPortContext)
let modalPosStyle = array([
viewStyle(~flex=1., ~width=100.->pct, ~height=100.->pct, ~alignItems=#center, ()),
switch modalPosition {
Expand Down Expand Up @@ -51,7 +53,7 @@ let make = (
~borderBottomLeftRadius=0.,
~borderBottomRightRadius=0.,
~overflow=#hidden,
~maxHeight=95.->pct,
~maxHeight=viewPortContants.maxPaymentSheetHeight->pct,
~alignItems=#center,
~justifyContent=#center,
(),
Expand All @@ -67,15 +69,42 @@ module Wrapper = {
@react.component
let make = (~onModalClose, ~width=100.->pct, ~children=React.null) => {
let {bgColor} = ThemebasedStyle.useThemeBasedStyle()
let (viewPortContants, _) = React.useContext(ViewportContext.viewPortContext)

let maxScrollViewHeight =
viewPortContants.windowHeight *. viewPortContants.maxPaymentSheetHeight /. 100. -.
viewPortContants.navigationBarHeight
let (isScrollable, setIsScrollable) = React.useState(_ => false)

<Animated.ScrollView
<ScrollView
onLayout={event => {
let height = event.nativeEvent.layout.height
if height > maxScrollViewHeight {
setIsScrollable(_ => true)
} else {
setIsScrollable(_ => false)
}
}}
contentContainerStyle={viewStyle(
~paddingBottom=isScrollable
? (viewPortContants.navigationBarHeight +. 15.)->dp
: viewPortContants.navigationBarHeight->dp,
(),
)}
keyboardShouldPersistTaps={#handled}
style={array([
viewStyle(~flexGrow=1., ~width, ~minHeight=250.->dp, ~padding=20.->dp, ()),
viewStyle(
~flexGrow=1.,
~width,
~minHeight=250.->dp,
~paddingHorizontal=20.->dp,
~paddingTop=20.->dp,
(),
),
bgColor,
])}>
<ModalHeader onModalClose />
children
</Animated.ScrollView>
</ScrollView>
}
}
2 changes: 0 additions & 2 deletions src/components/elements/ConfirmButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let make = (
~paymentMethod: string,
~paymentExperience=?,
~errorText=None,
~bottomSpace=0.,
) => {
let (nativeProp, _) = React.useContext(NativePropContext.nativePropContext)
let (allApiData, _) = React.useContext(AllApiDataContext.allApiDataContext)
Expand Down Expand Up @@ -35,6 +34,5 @@ let make = (
: localeObject.payNowButton
}}
/>}
{bottomSpace > 0. ? <Space height={bottomSpace} /> : React.null}
</>
}
37 changes: 37 additions & 0 deletions src/contexts/ViewportContext.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type viewPortContants = {
windowHeight: float,
navigationBarHeight: float,
maxPaymentSheetHeight: float,
}

let defaultNavbarHeight = 25.
let windowHeight = ReactNative.Dimensions.get(#window).height
let screenHeight = ReactNative.Dimensions.get(#screen).height
let statusBarHeight = ReactNative.StatusBar.currentHeight

let navigationBarHeight = if ReactNative.Platform.os !== #android {
defaultNavbarHeight
} else {
let navigationHeight = screenHeight -. windowHeight -. statusBarHeight
Math.min(75., Math.max(0., navigationHeight) +. defaultNavbarHeight)
}

let maxPaymentSheetHeight = 95. // pct

let defaultVal: viewPortContants = {windowHeight, navigationBarHeight, maxPaymentSheetHeight}

let viewPortContext = React.createContext((defaultVal, (_: viewPortContants) => ()))

module Provider = {
let make = React.Context.provider(viewPortContext)
}
@react.component
let make = (~children) => {
let (state, setState) = React.useState(_ => defaultVal)

let setState = React.useCallback1(val => {
setState(_ => val)
}, [setState])

<Provider value=(state, setState)> children </Provider>
}
16 changes: 9 additions & 7 deletions src/routes/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ module ContextWrapper = {
<NativePropContext nativeProp={SdkTypes.nativeJsonToRecord(props, rootTag)}>
<PaymentScreenContext>
<ThemeContext>
<LoggerContext>
<CardDataContext>
<AllApiDataContext>
<CustomKeyboardAvoidingView> children </CustomKeyboardAvoidingView>
</AllApiDataContext>
</CardDataContext>
</LoggerContext>
<ViewportContext>
<LoggerContext>
<CardDataContext>
<AllApiDataContext>
<CustomKeyboardAvoidingView> children </CustomKeyboardAvoidingView>
</AllApiDataContext>
</CardDataContext>
</LoggerContext>
</ViewportContext>
</ThemeContext>
</PaymentScreenContext>
</NativePropContext>
Expand Down
11 changes: 0 additions & 11 deletions src/routes/FullScreenSheetWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ let make = (~children) => {
None
}, [loading])

let navigationBarHeight = React.useMemo(() => {
if Platform.os !== #android {
0.
} else {
let screenHeight = Dimensions.get(#screen).height
let windowHeight = Dimensions.get(#window).height
screenHeight -. windowHeight
}
}, [])

<View
style={viewStyle(
~flex=1.,
Expand All @@ -80,7 +70,6 @@ let make = (~children) => {
<CustomView onDismiss=onModalClose>
<CustomView.Wrapper onModalClose>
{children}
<Space height={navigationBarHeight} />
</CustomView.Wrapper>
</CustomView>
</Animated.View>
Expand Down
5 changes: 1 addition & 4 deletions src/routes/GlobalConfirmButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ open ReactNative

@react.component
let make = (~confirmButtonDataRef) => {
<View>
{confirmButtonDataRef}
<Space />
</View>
<View> {confirmButtonDataRef} </View>
}
Loading