-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native] bottom sheet for exploring communities
Summary: in a subsequent diff, the buttons in this bottom sheet will lead to different navigations Test Plan: successfully navigated to and dismissed bottom sheet on android and ios. confirmed that the buttons were positioned correctly on multiple screen sizes {F3332425} Reviewers: ashoat Reviewed By: ashoat Subscribers: tomek Differential Revision: https://phab.comm.dev/D13986
- Loading branch information
Showing
5 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,97 @@ | ||
// @flow | ||
|
||
import invariant from 'invariant'; | ||
import * as React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import DirectoryPrompt from './directory-prompt.react.js'; | ||
import PrimaryButton from './primary-button.react.js'; | ||
import { BottomSheetContext } from '../bottom-sheet/bottom-sheet-provider.react.js'; | ||
import BottomSheet from '../bottom-sheet/bottom-sheet.react.js'; | ||
import type { RootNavigationProp } from '../navigation/root-navigator.react.js'; | ||
import type { NavigationRoute } from '../navigation/route-names.js'; | ||
|
||
const directoryPromptHeight = 293; | ||
const marginBottom = 10; | ||
const buttonHeight = 61; | ||
|
||
type Props = { | ||
+navigation: RootNavigationProp<'DirectoryPromptBottomSheet'>, | ||
+route: NavigationRoute<'DirectoryPromptBottomSheet'>, | ||
}; | ||
|
||
function DirectoryPromptBottomSheet(props: Props): React.Node { | ||
const { navigation } = props; | ||
|
||
const { goBack } = navigation; | ||
|
||
const bottomSheetRef = React.useRef(null); | ||
|
||
const bottomSheetContext = React.useContext(BottomSheetContext); | ||
invariant(bottomSheetContext, 'bottomSheetContext should be set'); | ||
const { setContentHeight } = bottomSheetContext; | ||
|
||
const insets = useSafeAreaInsets(); | ||
|
||
React.useLayoutEffect(() => { | ||
setContentHeight( | ||
directoryPromptHeight + | ||
marginBottom + | ||
buttonHeight + | ||
buttonHeight + | ||
insets.bottom, | ||
); | ||
}, [insets.bottom, setContentHeight]); | ||
|
||
const onPressAccept = React.useCallback(() => { | ||
console.log('User accepted the prompt'); | ||
}, []); | ||
|
||
const onPressDecline = React.useCallback(() => { | ||
console.log('User declined the prompt'); | ||
}, []); | ||
|
||
const directoryPromptBottomSheet = React.useMemo( | ||
() => ( | ||
<BottomSheet ref={bottomSheetRef} onClosed={goBack}> | ||
<View style={styles.container}> | ||
<View style={styles.promptContainer}> | ||
<DirectoryPrompt /> | ||
</View> | ||
<View style={styles.buttonContainer}> | ||
<PrimaryButton | ||
onPress={onPressAccept} | ||
label="Explore communities" | ||
variant="enabled" | ||
/> | ||
<PrimaryButton | ||
onPress={onPressDecline} | ||
label="No thanks" | ||
variant="outline" | ||
/> | ||
</View> | ||
</View> | ||
</BottomSheet> | ||
), | ||
[goBack, onPressAccept, onPressDecline], | ||
); | ||
|
||
return directoryPromptBottomSheet; | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
buttonContainer: { | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
}, | ||
container: { | ||
flex: 1, | ||
paddingHorizontal: 16, | ||
}, | ||
promptContainer: { | ||
marginBottom, | ||
}, | ||
}); | ||
|
||
export default DirectoryPromptBottomSheet; |
This file contains 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,56 @@ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
import { View, Text } from 'react-native'; | ||
|
||
import { useStyles } from '../themes/colors.js'; | ||
import CommunityPreviewIcon from '../vectors/community-preview-icon.react.js'; | ||
|
||
function DirectoryPrompt(): React.Node { | ||
const headerText = 'Discover communities'; | ||
const bodyText = 'Want to join some communities on Comm?'; | ||
|
||
const styles = useStyles(unboundStyles); | ||
const directoryPrompt = React.useMemo( | ||
() => ( | ||
<> | ||
<Text style={styles.header}>{headerText}</Text> | ||
<Text style={styles.body}>{bodyText}</Text> | ||
<View style={styles.communityLogoContainer}> | ||
<CommunityPreviewIcon /> | ||
</View> | ||
</> | ||
), | ||
[ | ||
bodyText, | ||
headerText, | ||
styles.body, | ||
styles.communityLogoContainer, | ||
styles.header, | ||
], | ||
); | ||
|
||
return directoryPrompt; | ||
} | ||
|
||
const unboundStyles = { | ||
header: { | ||
fontSize: 24, | ||
color: 'panelForegroundLabel', | ||
paddingBottom: 16, | ||
}, | ||
body: { | ||
fontFamily: 'Arial', | ||
fontSize: 15, | ||
lineHeight: 20, | ||
color: 'panelForegroundSecondaryLabel', | ||
paddingBottom: 16, | ||
}, | ||
communityLogoContainer: { | ||
flexGrow: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}; | ||
|
||
export default DirectoryPrompt; |
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.