Skip to content

Commit

Permalink
Dynamically mount modal's children according to their "scrollability"
Browse files Browse the repository at this point in the history
  • Loading branch information
mvaivre committed Oct 16, 2024
1 parent 690aa7b commit 7fdfa69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/mobile-wallet/src/features/modals/BottomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const BottomModal = ({
<AnimatedScrollView
onContentSizeChange={modalState.handleContentSizeChange}
keyboardShouldPersistTaps="handled"
scrollEnabled={modalState.isScrollable}
scrollEnabled={modalState.isContentScrollable}
scrollEventThrottle={16}
contentContainerStyle={[
contentContainerStyle,
Expand Down
22 changes: 13 additions & 9 deletions apps/mobile-wallet/src/features/modals/BottomModalBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { ReactNode } from 'react'
import { KeyboardAvoidingView, Pressable } from 'react-native'
import { KeyboardAvoidingView, Pressable, View } from 'react-native'
import { GestureDetector } from 'react-native-gesture-handler'
import Animated from 'react-native-reanimated'
import styled from 'styled-components/native'
Expand Down Expand Up @@ -50,6 +50,7 @@ const BottomModalBase = ({
panGesture,
navHeight,
title,
isContentScrollable,
children
}: BottomModalBaseProps) => (
<KeyboardAvoidingViewStyled behavior="height" enabled={!maximisedContent}>
Expand All @@ -60,15 +61,18 @@ const BottomModalBase = ({
<Handle style={handleAnimatedStyle} />
</HandleContainer>
<GestureDetector gesture={panGesture}>
<Navigation style={{ height: navHeight }}>
<NavigationButtonContainer align="left" />
<Title semiBold>{title}</Title>
<NavigationButtonContainer align="right">
<CloseButton onPress={handleClose} compact />
</NavigationButtonContainer>
</Navigation>
<View>
<Navigation style={{ height: navHeight }}>
<NavigationButtonContainer align="left" />
<Title semiBold>{title}</Title>
<NavigationButtonContainer align="right">
<CloseButton onPress={handleClose} compact />
</NavigationButtonContainer>
</Navigation>
{!isContentScrollable && children}
</View>
</GestureDetector>
{children}
{isContentScrollable && children}
</ModalStyled>
</Container>
</KeyboardAvoidingViewStyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const useBottomModalState = ({

const offsetY = useSharedValue(0)

const [isScrollable, setIsScrollable] = useState(false)
const [isContentScrollable, setIsContentScrollable] = useState(false)

const isModalClosing = useAppSelector((s) => selectModalById(s, modalId)?.isClosing)

Expand Down Expand Up @@ -134,7 +134,7 @@ export const useBottomModalState = ({
shouldMaximizeOnOpen.value ? handleMaximize() : handleMinimize()

// Determine if scrolling is needed
runOnJS(setIsScrollable)(contentHeight.value > dimensions.height * 0.9)
runOnJS(setIsContentScrollable)(contentHeight.value > dimensions.height * 0.9)
})()
}
},
Expand Down Expand Up @@ -257,6 +257,6 @@ export const useBottomModalState = ({
panGesture,
handleClose,
contentScrollHandlers,
isScrollable
isContentScrollable
}
}

0 comments on commit 7fdfa69

Please sign in to comment.