diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-03-22 15:36:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 15:36:10 +0000 |
commit | b27a0b8c97c1b82cc8a5f4318735d14a2358e979 (patch) | |
tree | 6d6f7ad4674e8b659f84bb6908378306142ebdb7 /src | |
parent | 772d528145e346273e8064624359da2e8db212ad (diff) | |
parent | 4ec434926e70e90cdca3e5f3205b834c62859dde (diff) | |
download | voidsky-b27a0b8c97c1b82cc8a5f4318735d14a2358e979.tar.zst |
Merge pull request #3337 from bluesky-social/samuel/scrollable-loggedoutlayout
Move scrollview to `LoggedOutLayout` to fix scrolling on web
Diffstat (limited to 'src')
-rw-r--r-- | src/screens/Login/FormContainer.tsx | 41 | ||||
-rw-r--r-- | src/screens/Login/index.tsx | 6 | ||||
-rw-r--r-- | src/screens/Signup/StepCaptcha/index.tsx | 33 | ||||
-rw-r--r-- | src/screens/Signup/index.tsx | 41 | ||||
-rw-r--r-- | src/view/com/util/layouts/LoggedOutLayout.tsx | 55 |
5 files changed, 95 insertions, 81 deletions
diff --git a/src/screens/Login/FormContainer.tsx b/src/screens/Login/FormContainer.tsx index e28b48b40..0144a8b5b 100644 --- a/src/screens/Login/FormContainer.tsx +++ b/src/screens/Login/FormContainer.tsx @@ -1,13 +1,6 @@ import React from 'react' -import { - ScrollView, - type StyleProp, - StyleSheet, - View, - type ViewStyle, -} from 'react-native' +import {type StyleProp, View, type ViewStyle} from 'react-native' -import {isWeb} from '#/platform/detection' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Text} from '#/components/Typography' @@ -16,38 +9,24 @@ export function FormContainer({ title, children, style, - contentContainerStyle, }: { testID?: string title?: React.ReactNode children: React.ReactNode style?: StyleProp<ViewStyle> - contentContainerStyle?: StyleProp<ViewStyle> }) { const {gtMobile} = useBreakpoints() const t = useTheme() return ( - <ScrollView + <View testID={testID} - style={[styles.maxHeight, contentContainerStyle]} - keyboardShouldPersistTaps="handled"> - <View - style={[a.gap_md, a.flex_1, !gtMobile && [a.px_lg, a.pt_md], style]}> - {title && !gtMobile && ( - <Text style={[a.text_xl, a.font_bold, t.atoms.text_contrast_high]}> - {title} - </Text> - )} - {children} - </View> - </ScrollView> + style={[a.gap_md, a.flex_1, !gtMobile && [a.px_lg, a.py_md], style]}> + {title && !gtMobile && ( + <Text style={[a.text_xl, a.font_bold, t.atoms.text_contrast_high]}> + {title} + </Text> + )} + {children} + </View> ) } - -const styles = StyleSheet.create({ - maxHeight: { - // @ts-ignore web only -prf - maxHeight: isWeb ? '100vh' : undefined, - height: !isWeb ? '100%' : undefined, - }, -}) diff --git a/src/screens/Login/index.tsx b/src/screens/Login/index.tsx index 49f7518b0..1fce63d29 100644 --- a/src/screens/Login/index.tsx +++ b/src/screens/Login/index.tsx @@ -164,7 +164,11 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { return ( <KeyboardAvoidingView testID="signIn" behavior="padding" style={a.flex_1}> - <LoggedOutLayout leadin="" title={title} description={description}> + <LoggedOutLayout + leadin="" + title={title} + description={description} + scrollable> <LayoutAnimationConfig skipEntering skipExiting> <ScreenTransition key={currentForm}>{content}</ScreenTransition> </LayoutAnimationConfig> diff --git a/src/screens/Signup/StepCaptcha/index.tsx b/src/screens/Signup/StepCaptcha/index.tsx index 311c697e7..2429b0c5e 100644 --- a/src/screens/Signup/StepCaptcha/index.tsx +++ b/src/screens/Signup/StepCaptcha/index.tsx @@ -1,11 +1,10 @@ import React from 'react' -import {ActivityIndicator, StyleSheet, View} from 'react-native' +import {ActivityIndicator, View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {nanoid} from 'nanoid/non-secure' import {createFullHandle} from '#/lib/strings/handles' -import {isWeb} from '#/platform/detection' import {ScreenTransition} from '#/screens/Login/ScreenTransition' import {useSignupContext, useSubmitSignup} from '#/screens/Signup/state' import {CaptchaWebView} from '#/screens/Signup/StepCaptcha/CaptchaWebView' @@ -54,7 +53,14 @@ export function StepCaptcha() { return ( <ScreenTransition> <View style={[a.gap_lg]}> - <View style={[styles.container, completed && styles.center]}> + <View + style={[ + a.w_full, + a.pb_xl, + a.overflow_hidden, + {minHeight: 500}, + completed && [a.align_center, a.justify_center], + ]}> {!completed ? ( <CaptchaWebView url={url} @@ -72,24 +78,3 @@ export function StepCaptcha() { </ScreenTransition> ) } - -const styles = StyleSheet.create({ - error: { - borderRadius: 6, - marginTop: 10, - }, - // @ts-expect-error: Suppressing error due to incomplete `ViewStyle` type definition in react-native-web, missing `cursor` prop as discussed in https://github.com/necolas/react-native-web/issues/832. - touchable: { - ...(isWeb && {cursor: 'pointer'}), - }, - container: { - minHeight: 500, - width: '100%', - paddingBottom: 20, - overflow: 'hidden', - }, - center: { - alignItems: 'center', - justifyContent: 'center', - }, -}) diff --git a/src/screens/Signup/index.tsx b/src/screens/Signup/index.tsx index b84f4d0d7..4211194c7 100644 --- a/src/screens/Signup/index.tsx +++ b/src/screens/Signup/index.tsx @@ -1,5 +1,6 @@ import React from 'react' -import {ScrollView, View} from 'react-native' +import {View} from 'react-native' +import {LayoutAnimationConfig} from 'react-native-reanimated' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -20,7 +21,7 @@ import { import {StepCaptcha} from '#/screens/Signup/StepCaptcha' import {StepHandle} from '#/screens/Signup/StepHandle' import {StepInfo} from '#/screens/Signup/StepInfo' -import {atoms as a, useTheme} from '#/alf' +import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import {Divider} from '#/components/Divider' import {InlineLink} from '#/components/Link' @@ -32,6 +33,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { const {screen} = useAnalytics() const [state, dispatch] = React.useReducer(reducer, initialState) const submit = useSubmitSignup({state, dispatch}) + const {gtMobile} = useBreakpoints() const { data: serviceInfo, @@ -125,13 +127,16 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { <LoggedOutLayout leadin="" title={_(msg`Create Account`)} - description={_(msg`We're so excited to have you join us!`)}> - <ScrollView - testID="createAccount" - keyboardShouldPersistTaps="handled" - style={a.h_full} - keyboardDismissMode="on-drag"> - <View style={[a.flex_1, a.px_xl, a.pt_2xl, {paddingBottom: 100}]}> + description={_(msg`We're so excited to have you join us!`)} + scrollable> + <View testID="createAccount" style={a.flex_1}> + <View + style={[ + a.flex_1, + a.px_xl, + a.pt_2xl, + !gtMobile && {paddingBottom: 100}, + ]}> <View style={[a.gap_sm, a.pb_3xl]}> <Text style={[a.font_semibold, t.atoms.text_contrast_medium]}> <Trans>Step</Trans> {state.activeStep + 1} <Trans>of</Trans>{' '} @@ -152,13 +157,15 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { </View> <View style={[a.pb_3xl]}> - {state.activeStep === SignupStep.INFO ? ( - <StepInfo /> - ) : state.activeStep === SignupStep.HANDLE ? ( - <StepHandle /> - ) : ( - <StepCaptcha /> - )} + <LayoutAnimationConfig skipEntering skipExiting> + {state.activeStep === SignupStep.INFO ? ( + <StepInfo /> + ) : state.activeStep === SignupStep.HANDLE ? ( + <StepHandle /> + ) : ( + <StepCaptcha /> + )} + </LayoutAnimationConfig> </View> <View style={[a.flex_row, a.justify_between, a.pb_lg]}> @@ -208,7 +215,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { </Text> </View> </View> - </ScrollView> + </View> </LoggedOutLayout> </SignupContext.Provider> ) diff --git a/src/view/com/util/layouts/LoggedOutLayout.tsx b/src/view/com/util/layouts/LoggedOutLayout.tsx index 9424a7154..0272a44c6 100644 --- a/src/view/com/util/layouts/LoggedOutLayout.tsx +++ b/src/view/com/util/layouts/LoggedOutLayout.tsx @@ -1,19 +1,24 @@ import React from 'react' -import {StyleSheet, View} from 'react-native' -import {Text} from '../text/Text' +import {ScrollView, StyleSheet, View} from 'react-native' + +import {isWeb} from '#/platform/detection' +import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' import {usePalette} from 'lib/hooks/usePalette' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' -import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' +import {atoms as a} from '#/alf' +import {Text} from '../text/Text' export const LoggedOutLayout = ({ leadin, title, description, children, + scrollable, }: React.PropsWithChildren<{ leadin: string title: string description: string + scrollable?: boolean }>) => { const {isMobile, isTabletOrMobile} = useWebMediaQueries() const pal = usePalette('default') @@ -25,7 +30,18 @@ export const LoggedOutLayout = ({ }) if (isMobile) { - return <View style={{paddingTop: 10}}>{children}</View> + if (scrollable) { + return ( + <ScrollView + style={styles.scrollview} + keyboardShouldPersistTaps="handled" + keyboardDismissMode="on-drag"> + <View style={a.pt_md}>{children}</View> + </ScrollView> + ) + } else { + return <View style={a.pt_md}>{children}</View> + } } return ( <View style={styles.container}> @@ -50,9 +66,23 @@ export const LoggedOutLayout = ({ {description} </Text> </View> - <View style={[styles.content, contentBg]}> - <View style={styles.contentWrapper}>{children}</View> - </View> + {scrollable ? ( + <View style={[styles.scrollableContent, contentBg]}> + <ScrollView + style={styles.scrollview} + contentContainerStyle={styles.scrollViewContentContainer} + keyboardShouldPersistTaps="handled" + keyboardDismissMode="on-drag"> + <View style={[styles.contentWrapper, isWeb && a.my_auto]}> + {children} + </View> + </ScrollView> + </View> + ) : ( + <View style={[styles.content, contentBg]}> + <View style={styles.contentWrapper}>{children}</View> + </View> + )} </View> ) } @@ -74,7 +104,16 @@ const styles = StyleSheet.create({ paddingHorizontal: 40, justifyContent: 'center', }, - + scrollableContent: { + flex: 2, + }, + scrollview: { + flex: 1, + }, + scrollViewContentContainer: { + flex: 1, + paddingHorizontal: 40, + }, leadinText: { fontSize: 36, fontWeight: '800', |