diff options
Diffstat (limited to 'src/components/common')
-rw-r--r-- | src/components/common/BottomDrawer.tsx | 118 | ||||
-rw-r--r-- | src/components/common/SocialLinkModal.tsx | 3 | ||||
-rw-r--r-- | src/components/common/TaggDatePicker.tsx | 22 | ||||
-rw-r--r-- | src/components/common/index.ts | 1 |
4 files changed, 133 insertions, 11 deletions
diff --git a/src/components/common/BottomDrawer.tsx b/src/components/common/BottomDrawer.tsx new file mode 100644 index 00000000..bef9434a --- /dev/null +++ b/src/components/common/BottomDrawer.tsx @@ -0,0 +1,118 @@ +import React, {Fragment, ReactText, useEffect, useRef, useState} from 'react'; +import { + Modal, + StyleSheet, + TouchableWithoutFeedback, + View, + ViewProps, +} from 'react-native'; +import Animated from 'react-native-reanimated'; +import BottomSheet from 'reanimated-bottom-sheet'; +import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; + +interface BottomDrawerProps extends ViewProps { + initialSnapPosition?: ReactText; + isOpen: boolean; + setIsOpen: (open: boolean) => void; + showHeader: boolean; +} + +// More examples here: +// https://github.com/osdnk/react-native-reanimated-bottom-sheet/tree/master/Example +const BottomDrawer: React.FC<BottomDrawerProps> = (props) => { + const {isOpen, setIsOpen, showHeader, initialSnapPosition} = props; + const drawerRef = useRef<BottomSheet>(null); + const [modalVisible, setModalVisible] = useState(isOpen); + const bgAlpha = new Animated.Value(isOpen ? 1 : 0); + + useEffect(() => { + if (isOpen) { + setModalVisible(true); + } else { + bgAlpha.setValue(0); + drawerRef.current && drawerRef.current.snapTo(1); + } + }, [isOpen]); + + const renderContent = () => { + return <View>{props.children}</View>; + }; + + const renderHeader = () => { + return showHeader ? ( + <View style={styles.header}> + <View style={styles.panelHeader}> + <View style={styles.panelHandle} /> + </View> + </View> + ) : ( + <Fragment /> + ); + }; + + return ( + <Modal + transparent + visible={modalVisible} + onShow={() => { + drawerRef.current && drawerRef.current.snapTo(0); + }}> + <BottomSheet + ref={drawerRef} + snapPoints={[initialSnapPosition ?? '30%', 0]} + initialSnap={1} + renderContent={renderContent} + renderHeader={renderHeader} + enabledContentGestureInteraction={false} + callbackNode={bgAlpha} + onCloseEnd={() => { + setModalVisible(false); + setIsOpen(false); + }} + /> + + <TouchableWithoutFeedback + onPress={() => { + setIsOpen(false); + }}> + <Animated.View + style={[ + styles.backgroundView, + { + backgroundColor: Animated.interpolateColors(bgAlpha, { + inputRange: [0, 1], + outputColorRange: ['rgba(0,0,0,0.3)', 'rgba(0,0,0,0)'], + }), + }, + ]} + /> + </TouchableWithoutFeedback> + </Modal> + ); +}; + +const styles = StyleSheet.create({ + header: { + backgroundColor: '#f7f5eee8', + shadowColor: '#000000', + paddingTop: 20, + borderTopLeftRadius: 20, + borderTopRightRadius: 20, + }, + panelHeader: { + alignItems: 'center', + }, + panelHandle: { + width: 40, + height: 8, + borderRadius: 4, + backgroundColor: '#00000040', + marginBottom: 10, + }, + backgroundView: { + height: SCREEN_HEIGHT, + width: SCREEN_WIDTH, + }, +}); + +export default BottomDrawer; diff --git a/src/components/common/SocialLinkModal.tsx b/src/components/common/SocialLinkModal.tsx index 3cea2567..b307a62c 100644 --- a/src/components/common/SocialLinkModal.tsx +++ b/src/components/common/SocialLinkModal.tsx @@ -1,6 +1,7 @@ import React from 'react'; import {Modal, StyleSheet, Text, TouchableHighlight, View} from 'react-native'; import {TextInput} from 'react-native-gesture-handler'; +import { TAGG_TEXT_LIGHT_BLUE } from '../../constants'; import {SCREEN_WIDTH} from '../../utils'; interface SocialLinkModalProps { @@ -104,7 +105,7 @@ const styles = StyleSheet.create({ fontSize: 14, /* identical to box height */ textAlign: 'center', - color: '#698DD3', + color: TAGG_TEXT_LIGHT_BLUE, }, textInput: { height: 20, diff --git a/src/components/common/TaggDatePicker.tsx b/src/components/common/TaggDatePicker.tsx index d8010251..059bf620 100644 --- a/src/components/common/TaggDatePicker.tsx +++ b/src/components/common/TaggDatePicker.tsx @@ -1,3 +1,4 @@ +import moment from 'moment'; import React, {useState} from 'react'; import DatePicker from 'react-native-date-picker'; @@ -5,23 +6,24 @@ interface TaggDatePickerProps { handleDateUpdate: (_: Date) => void; maxDate: Date; textColor: string; + date: Date | undefined; } -const TaggDatePicker: React.FC<TaggDatePickerProps> = ({ - handleDateUpdate, - maxDate, - textColor, -}) => { - const [date, setDate] = useState(new Date()); +const TaggDatePicker: React.FC<TaggDatePickerProps> = (props) => { + const [date, setDate] = useState( + props.date + ? new Date(moment(props.date).add(1, 'day').format('YYYY-MM-DD')) + : undefined, + ); return ( <DatePicker - date={date} - textColor={textColor} + date={date ? date : props.maxDate} + textColor={props.textColor} mode={'date'} - maximumDate={maxDate} + maximumDate={props.maxDate} onDateChange={(newDate) => { setDate(newDate); - handleDateUpdate(newDate); + props.handleDateUpdate(newDate); }} /> ); diff --git a/src/components/common/index.ts b/src/components/common/index.ts index c7ed13cd..883dae61 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -13,4 +13,5 @@ export {default as SocialLinkModal} from './SocialLinkModal'; export {default as ComingSoon} from './ComingSoon'; export {default as PostCarousel} from './PostCarousel'; export {default as TaggDatePicker} from './TaggDatePicker'; +export {default as BottomDrawer} from './BottomDrawer'; export * from './post'; |