mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Composer - Use sheet presentation on iOS (#4278)

* use sheet presentation + tweak spacing

* line up elements + add hitslop to cancel

* fixing spacing on replies

authored by samuel.fm and committed by

GitHub 3bdceac2 76f860da

+51 -25
+11 -9
src/alf/util/useColorModeTheme.ts
··· 7 7 import {dark, dim, light, ThemeName} from '#/alf/themes' 8 8 9 9 export function useColorModeTheme(): ThemeName { 10 - const colorScheme = useColorScheme() 11 - const {colorMode, darkTheme} = useThemePrefs() 10 + const theme = useThemeName() 12 11 13 12 React.useLayoutEffect(() => { 14 - const theme = getThemeName(colorScheme, colorMode, darkTheme) 15 13 updateDocument(theme) 16 14 SystemUI.setBackgroundColorAsync(getBackgroundColor(theme)) 17 - }, [colorMode, colorScheme, darkTheme]) 15 + }, [theme]) 18 16 19 - return React.useMemo( 20 - () => getThemeName(colorScheme, colorMode, darkTheme), 21 - [colorScheme, colorMode, darkTheme], 22 - ) 17 + return theme 18 + } 19 + 20 + export function useThemeName(): ThemeName { 21 + const colorScheme = useColorScheme() 22 + const {colorMode, darkTheme} = useThemePrefs() 23 + 24 + return getThemeName(colorScheme, colorMode, darkTheme) 23 25 } 24 26 25 27 function getThemeName( ··· 53 55 } 54 56 } 55 57 56 - function getBackgroundColor(theme: ThemeName): string { 58 + export function getBackgroundColor(theme: ThemeName): string { 57 59 switch (theme) { 58 60 case 'light': 59 61 return light.atoms.bg.backgroundColor
+6 -9
src/view/com/composer/Composer.tsx
··· 54 54 import {useComposerControls} from '#/state/shell/composer' 55 55 import {useAnalytics} from 'lib/analytics/analytics' 56 56 import * as apilib from 'lib/api/index' 57 - import {MAX_GRAPHEME_LENGTH} from 'lib/constants' 57 + import {HITSLOP_10, MAX_GRAPHEME_LENGTH} from 'lib/constants' 58 58 import {useIsKeyboardVisible} from 'lib/hooks/useIsKeyboardVisible' 59 59 import {usePalette} from 'lib/hooks/usePalette' 60 60 import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' ··· 165 165 () => ({ 166 166 paddingBottom: 167 167 isAndroid || (isIOS && !isKeyboardVisible) ? insets.bottom : 0, 168 - paddingTop: isMobile && isWeb ? 15 : insets.top, 169 168 }), 170 - [insets, isKeyboardVisible, isMobile], 169 + [insets, isKeyboardVisible], 171 170 ) 172 171 173 172 const hasScrolled = useSharedValue(0) ··· 422 421 accessibilityLabel={_(msg`Cancel`)} 423 422 accessibilityHint={_( 424 423 msg`Closes post composer and discards post draft`, 425 - )}> 424 + )} 425 + hitSlop={HITSLOP_10}> 426 426 <Text style={[pal.link, s.f18]}> 427 427 <Trans>Cancel</Trans> 428 428 </Text> ··· 622 622 topbar: { 623 623 flexDirection: 'row', 624 624 alignItems: 'center', 625 - marginTop: -10, 626 - paddingHorizontal: 4, 627 625 marginHorizontal: 16, 628 - height: 44, 626 + height: 54, 629 627 gap: 4, 630 628 borderBottomWidth: StyleSheet.hairlineWidth, 631 629 }, ··· 633 631 paddingTop: 10, 634 632 paddingBottom: 10, 635 633 height: 50, 636 - marginTop: 0, 637 634 }, 638 635 postBtn: { 639 636 borderRadius: 20, ··· 676 673 }, 677 674 textInputLayout: { 678 675 flexDirection: 'row', 679 - paddingTop: 16, 676 + paddingTop: 4, 680 677 }, 681 678 textInputLayoutMobile: { 682 679 flex: 1,
+2 -1
src/view/com/composer/ComposerReplyTo.tsx
··· 223 223 flexDirection: 'row', 224 224 alignItems: 'flex-start', 225 225 borderBottomWidth: StyleSheet.hairlineWidth, 226 - paddingTop: 16, 226 + paddingTop: 4, 227 227 paddingBottom: 16, 228 + marginBottom: 12, 228 229 }, 229 230 replyToPost: { 230 231 flex: 1,
+32 -6
src/view/shell/Composer.tsx
··· 1 - import React from 'react' 1 + import React, {useLayoutEffect} from 'react' 2 2 import {Modal, View} from 'react-native' 3 + import {StatusBar} from 'expo-status-bar' 4 + import * as SystemUI from 'expo-system-ui' 3 5 import {observer} from 'mobx-react-lite' 4 6 7 + import {isIOS} from '#/platform/detection' 5 8 import {Provider as LegacyModalProvider} from '#/state/modals' 6 - import {useComposerState} from 'state/shell/composer' 9 + import {useComposerState} from '#/state/shell/composer' 7 10 import {ModalsContainer as LegacyModalsContainer} from '#/view/com/modals/Modal' 8 - import {useTheme} from '#/alf' 11 + import {atoms as a, useTheme} from '#/alf' 12 + import {getBackgroundColor, useThemeName} from '#/alf/util/useColorModeTheme' 9 13 import { 10 14 Outlet as PortalOutlet, 11 15 Provider as PortalProvider, ··· 19 23 const state = useComposerState() 20 24 const ref = useComposerCancelRef() 21 25 26 + const open = !!state 27 + 22 28 return ( 23 29 <Modal 24 30 aria-modal 25 31 accessibilityViewIsModal 26 - visible={!!state} 27 - presentationStyle="overFullScreen" 32 + visible={open} 33 + presentationStyle="formSheet" 28 34 animationType="slide" 29 35 onRequestClose={() => ref.current?.onPressCancel()}> 30 - <View style={[t.atoms.bg, {flex: 1}]}> 36 + <View style={[t.atoms.bg, a.flex_1]}> 31 37 <LegacyModalProvider> 32 38 <PortalProvider> 33 39 <ComposePost ··· 43 49 <PortalOutlet /> 44 50 </PortalProvider> 45 51 </LegacyModalProvider> 52 + {isIOS && <IOSModalBackground active={open} />} 46 53 </View> 47 54 </Modal> 48 55 ) 49 56 }) 57 + 58 + // Generally, the backdrop of the app is the theme color, but when this is open 59 + // we want it to be black due to the modal being a form sheet. 60 + function IOSModalBackground({active}: {active: boolean}) { 61 + const theme = useThemeName() 62 + 63 + useLayoutEffect(() => { 64 + SystemUI.setBackgroundColorAsync('black') 65 + 66 + return () => { 67 + SystemUI.setBackgroundColorAsync(getBackgroundColor(theme)) 68 + } 69 + }, [theme]) 70 + 71 + // Set the status bar to light - however, only if the modal is active 72 + // If we rely on this component being mounted to set this, 73 + // there'll be a delay before it switches back to default. 74 + return active ? <StatusBar style="light" animated /> : null 75 + }