-
Notifications
You must be signed in to change notification settings - Fork 0
feat: bottom sheet component #231
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
Merged
Tania-Roche-SWO
merged 5 commits into
main
from
feature/MPT-18946/bottom-sheet-component
Mar 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b37fb89
Creating bottom sheet component, adding animation, drag gesture suppo…
Tania-Roche-SWO f51f395
Merge branch 'main' into feature/MPT-18946/bottom-sheet-component
Tania-Roche-SWO 0147585
Adding chat wizard to chat screen, hooking up to nav icon
Tania-Roche-SWO 6f56e41
Addressing PR comments
Tania-Roche-SWO 24b662c
Merge branch 'main' into feature/MPT-18946/bottom-sheet-component
Tania-Roche-SWO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,112 @@ | ||
| import { useEffect, useRef, useState } from 'react'; | ||
| import { | ||
| Animated, | ||
| Dimensions, | ||
| Modal, | ||
| PanResponder, | ||
| Pressable, | ||
| StyleSheet, | ||
| View, | ||
| } from 'react-native'; | ||
|
|
||
| import { bottomSheetStyle } from '@/styles'; | ||
|
|
||
| type BottomSheetProps = { | ||
| visible: boolean; | ||
| onClose: () => void; | ||
| children: React.ReactNode; | ||
| snapHeight?: number; | ||
| testID: string; | ||
| }; | ||
|
|
||
| const SCREEN_HEIGHT = Dimensions.get('window').height; | ||
| const DEFAULT_SNAP_HEIGHT = 0.9; | ||
| const CLOSE_THRESHOLD = 120; | ||
| const DRAG_ACTIVATION_THRESHOLD = 5; | ||
|
|
||
| const BottomSheet = ({ | ||
| visible, | ||
| onClose, | ||
| children, | ||
| snapHeight = DEFAULT_SNAP_HEIGHT, | ||
| }: BottomSheetProps) => { | ||
| const [internalVisible, setInternalVisible] = useState(false); | ||
| const translateY = useRef(new Animated.Value(SCREEN_HEIGHT)).current; | ||
| const SHEET_MAX_HEIGHT = SCREEN_HEIGHT * snapHeight; | ||
|
|
||
| const sheetMaxHeightRef = useRef(SHEET_MAX_HEIGHT); | ||
|
|
||
| useEffect(() => { | ||
| sheetMaxHeightRef.current = SCREEN_HEIGHT * snapHeight; | ||
| }, [snapHeight]); | ||
|
|
||
| const panResponder = useRef( | ||
| PanResponder.create({ | ||
| onStartShouldSetPanResponder: () => true, | ||
| onMoveShouldSetPanResponder: (_, gestureState) => | ||
| Math.abs(gestureState.dy) > DRAG_ACTIVATION_THRESHOLD, | ||
| onPanResponderMove: (_, gestureState) => { | ||
| const sheetMaxHeight = sheetMaxHeightRef.current; | ||
| const newY = SCREEN_HEIGHT - sheetMaxHeight + gestureState.dy; | ||
| if (newY >= SCREEN_HEIGHT - sheetMaxHeight) { | ||
| translateY.setValue(newY); | ||
| } | ||
| }, | ||
| onPanResponderRelease: (_, gestureState) => { | ||
| if (gestureState.dy > CLOSE_THRESHOLD) { | ||
| onClose(); | ||
| } else { | ||
| Animated.spring(translateY, { | ||
| toValue: SCREEN_HEIGHT - sheetMaxHeightRef.current, | ||
| useNativeDriver: true, | ||
| stiffness: 100, | ||
| damping: 20, | ||
| }).start(); | ||
| } | ||
| }, | ||
| }), | ||
| ).current; | ||
|
|
||
| useEffect(() => { | ||
| if (visible) { | ||
| setInternalVisible(true); | ||
| Animated.spring(translateY, { | ||
| toValue: SCREEN_HEIGHT - sheetMaxHeightRef.current, | ||
| useNativeDriver: true, | ||
| stiffness: 250, | ||
| damping: 28, | ||
| mass: 1, | ||
| }).start(); | ||
| } else { | ||
| Animated.timing(translateY, { | ||
| toValue: SCREEN_HEIGHT, | ||
| duration: 220, | ||
| useNativeDriver: true, | ||
| }).start(() => setInternalVisible(false)); | ||
| } | ||
| }, [visible, translateY]); | ||
|
|
||
| if (!internalVisible) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Modal transparent animationType="none" visible={internalVisible}> | ||
| <Pressable style={styles.backdrop} onPress={onClose} /> | ||
| <Animated.View | ||
| style={[styles.sheet, { height: SHEET_MAX_HEIGHT, transform: [{ translateY }] }]} | ||
| > | ||
| <View style={styles.grabber} {...panResponder.panHandlers} /> | ||
| {children} | ||
| </Animated.View> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| backdrop: bottomSheetStyle.backdrop, | ||
| sheet: bottomSheetStyle.sheet, | ||
| grabber: bottomSheetStyle.grabber, | ||
| }); | ||
|
|
||
| export default BottomSheet; |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| { | ||
| "chatsScreen": { | ||
| "emptyStateTitle": "No chats", | ||
| "emptyStateDescription": "No chats found." | ||
| }, | ||
| "chatsScreen": { | ||
| "emptyStateTitle": "No chats", | ||
| "emptyStateDescription": "No chats found." | ||
| }, | ||
| "messagesScreen": { | ||
| "emptyStateTitle": "No messages", | ||
| "emptyStateDescription": "No messages in this conversation yet." | ||
| }, | ||
| "chat": { | ||
| "messageInputPlaceholder": "Type a message" | ||
| }, | ||
| "createChatWizard": { | ||
| "title": "Create chat", | ||
| "next": "Next", | ||
| "cancel": "Cancel" | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,132 @@ | ||
| import { useNavigation } from '@react-navigation/native'; | ||
| import type { StackNavigationProp } from '@react-navigation/stack'; | ||
| import { useState, useCallback } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { | ||
| View, | ||
| Text, | ||
| TextInput, | ||
| ScrollView, | ||
| StyleSheet, | ||
| KeyboardAvoidingView, | ||
| TouchableOpacity, | ||
| Platform, | ||
| Button, | ||
Tania-Roche-SWO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } from 'react-native'; | ||
|
|
||
| import BottomSheet from '@/components/modal/BottomSheet'; | ||
| import { createChatWizardStyle, inputStyle } from '@/styles'; | ||
| import type { RootStackParamList } from '@/types/navigation'; | ||
| import { TestIDs } from '@/utils/testID'; | ||
|
|
||
| type Props = { | ||
Tania-Roche-SWO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| visible: boolean; | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| const CreateChatModal = ({ visible, onClose }: Props) => { | ||
| const [step, setStep] = useState(0); | ||
| const [chatType, setChatType] = useState<'group' | 'direct' | null>(null); | ||
| const [chatName, setChatName] = useState(''); | ||
|
|
||
| const { t } = useTranslation(); | ||
|
|
||
| const navigation = useNavigation<StackNavigationProp<RootStackParamList>>(); | ||
|
|
||
| const handleClose = useCallback(() => { | ||
| setStep(0); | ||
| setChatType(null); | ||
| setChatName(''); | ||
| onClose(); | ||
| }, [onClose]); | ||
|
|
||
| const handleNext = () => { | ||
Tania-Roche-SWO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (step === 0) { | ||
| if (!chatType) return; | ||
| setStep(1); | ||
| } else if (step === 1) { | ||
| if (!chatName.trim()) return; | ||
| setStep(2); | ||
| } else if (step === 2) { | ||
| navigation.navigate('chatConversation', { id: 'CHT-123-4565' }); | ||
| handleClose(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <BottomSheet visible={visible} onClose={handleClose} testID={TestIDs.CHAT_CREATE_MODAL}> | ||
| <View style={styles.headerRow}> | ||
| <View style={styles.headerSide}> | ||
| <TouchableOpacity onPress={handleClose}> | ||
| <Text style={styles.headerTextCancel}>{t('createChatWizard.cancel')}</Text> | ||
| </TouchableOpacity> | ||
| </View> | ||
| <View style={styles.headerCenter}> | ||
| <Text style={styles.headerTitle}>{t('createChatWizard.title')}</Text> | ||
| </View> | ||
| <View style={styles.headerSide}> | ||
| {step > 0 && ( | ||
| <TouchableOpacity onPress={handleNext}> | ||
| <Text style={styles.headerTextNext}>{t('createChatWizard.next')}</Text> | ||
| </TouchableOpacity> | ||
| )} | ||
| </View> | ||
| </View> | ||
| <KeyboardAvoidingView | ||
| behavior="height" | ||
| keyboardVerticalOffset={Platform.OS === 'ios' ? 200 : 0} | ||
| > | ||
| {step === 0 && ( | ||
| <View> | ||
| <Button | ||
| title="Group Chat" | ||
| onPress={() => { | ||
| setChatType('group'); | ||
| setStep(1); | ||
| }} | ||
| /> | ||
| <Button | ||
| title="Direct Chat: John Doe" | ||
| onPress={() => { | ||
| handleClose(); | ||
| navigation.navigate('chatConversation', { id: 'CHT-234-2345' }); | ||
| }} | ||
| /> | ||
| </View> | ||
| )} | ||
|
|
||
| {step === 1 && ( | ||
| <View> | ||
| <TextInput | ||
| placeholder="Enter chat name" | ||
| value={chatName} | ||
| onChangeText={setChatName} | ||
| style={styles.input} | ||
| autoFocus | ||
| /> | ||
| </View> | ||
| )} | ||
|
|
||
| {step === 2 && ( | ||
| <View> | ||
| <ScrollView> | ||
| <Text>User list placeholder</Text> | ||
| </ScrollView> | ||
| </View> | ||
| )} | ||
| </KeyboardAvoidingView> | ||
| </BottomSheet> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| headerRow: createChatWizardStyle.headerRow, | ||
| headerSide: createChatWizardStyle.headerSide, | ||
| headerCenter: createChatWizardStyle.headerCenter, | ||
| headerTitle: createChatWizardStyle.headerTitle, | ||
| headerTextCancel: createChatWizardStyle.headerTextCancel, | ||
| headerTextNext: createChatWizardStyle.headerTextNext, | ||
| input: inputStyle.container, | ||
| }); | ||
|
|
||
| export default CreateChatModal; | ||
This file contains hidden or 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
This file contains hidden or 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,30 @@ | ||
| import { BorderRadius, Color, Spacing } from '../tokens'; | ||
|
|
||
| export const bottomSheetStyle = { | ||
| backdrop: { | ||
| position: 'absolute', | ||
| left: Spacing.spacing0, | ||
| right: Spacing.spacing0, | ||
| top: Spacing.spacing0, | ||
| bottom: Spacing.spacing0, | ||
| backgroundColor: Color.fills.overlay, | ||
| }, | ||
| sheet: { | ||
| position: 'absolute', | ||
| bottom: Spacing.spacing0, | ||
| width: '100%', | ||
| backgroundColor: Color.brand.white, | ||
| borderTopLeftRadius: BorderRadius.md, | ||
| borderTopRightRadius: BorderRadius.md, | ||
| paddingHorizontal: Spacing.spacing2, | ||
| paddingBottom: Spacing.spacing2, | ||
| }, | ||
| grabber: { | ||
| width: 36, | ||
| height: 5, | ||
| borderRadius: BorderRadius.xxs, | ||
| backgroundColor: Color.gray.gray3, | ||
| alignSelf: 'center', | ||
| marginTop: Spacing.spacingSmall6, | ||
| }, | ||
| } as const; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.