make sure rnkc is enabled globally

This commit is contained in:
Samuel Newman
2024-11-25 14:31:33 +00:00
parent 5164ca6288
commit 3a64c72293
3 changed files with 19 additions and 65 deletions
+17 -44
View File
@@ -5,15 +5,10 @@ import {
Pressable, Pressable,
ScrollView, ScrollView,
StyleProp, StyleProp,
TextInput,
View, View,
ViewStyle, ViewStyle,
} from 'react-native' } from 'react-native'
import { import {KeyboardAwareScrollView} from 'react-native-keyboard-controller'
KeyboardAwareScrollView,
useKeyboardController,
useKeyboardHandler,
} from 'react-native-keyboard-controller'
import {runOnJS} from 'react-native-reanimated' import {runOnJS} from 'react-native-reanimated'
import {ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/hook/commonTypes' import {ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/hook/commonTypes'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
@@ -22,18 +17,17 @@ import {useLingui} from '@lingui/react'
import {ScrollProvider} from '#/lib/ScrollContext' import {ScrollProvider} from '#/lib/ScrollContext'
import {logger} from '#/logger' import {logger} from '#/logger'
import {isAndroid, isIOS} from '#/platform/detection' import {isAndroid} from '#/platform/detection'
import {useA11y} from '#/state/a11y' import {useA11y} from '#/state/a11y'
import {useDialogStateControlContext} from '#/state/dialogs' import {useDialogStateControlContext} from '#/state/dialogs'
import {List, ListMethods, ListProps} from '#/view/com/util/List' import {List, ListMethods, ListProps} from '#/view/com/util/List'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, platform, useTheme} from '#/alf'
import {Context, useDialogContext} from '#/components/Dialog/context' import {Context, useDialogContext} from '#/components/Dialog/context'
import { import {
DialogControlProps, DialogControlProps,
DialogInnerProps, DialogInnerProps,
DialogOuterProps, DialogOuterProps,
} from '#/components/Dialog/types' } from '#/components/Dialog/types'
import {createInput} from '#/components/forms/TextField'
import {BottomSheet, BottomSheetSnapPoint} from '../../../modules/bottom-sheet' import {BottomSheet, BottomSheetSnapPoint} from '../../../modules/bottom-sheet'
import { import {
BottomSheetSnapPointChangeEvent, BottomSheetSnapPointChangeEvent,
@@ -45,8 +39,8 @@ export {useDialogContext, useDialogControl} from '#/components/Dialog/context'
export * from '#/components/Dialog/shared' export * from '#/components/Dialog/shared'
export * from '#/components/Dialog/types' export * from '#/components/Dialog/types'
export * from '#/components/Dialog/utils' export * from '#/components/Dialog/utils'
// @ts-ignore // holdover from when @gorhom/bottom-sheet required a special textinput
export const Input = createInput(TextInput) export {Input} from '#/components/forms/TextField'
export function Outer({ export function Outer({
children, children,
@@ -181,9 +175,7 @@ export function Inner({children, style, header}: DialogInnerProps) {
style={[ style={[
a.pt_2xl, a.pt_2xl,
a.px_xl, a.px_xl,
{ {paddingBottom: insets.bottom + insets.top},
paddingBottom: insets.bottom + insets.top,
},
style, style,
]}> ]}>
{children} {children}
@@ -199,35 +191,6 @@ export const ScrollableInner = React.forwardRef<ScrollView, DialogInnerProps>(
) { ) {
const {nativeSnapPoint, disableDrag, setDisableDrag} = useDialogContext() const {nativeSnapPoint, disableDrag, setDisableDrag} = useDialogContext()
const insets = useSafeAreaInsets() const insets = useSafeAreaInsets()
const {setEnabled} = useKeyboardController()
const [keyboardHeight, setKeyboardHeight] = React.useState(0)
React.useEffect(() => {
if (!isIOS) {
return
}
setEnabled(true)
return () => {
setEnabled(false)
}
})
useKeyboardHandler({
onEnd: e => {
'worklet'
runOnJS(setKeyboardHeight)(e.height)
},
})
const basePading =
(isIOS ? 30 : 50) + (isIOS ? keyboardHeight / 4 : keyboardHeight)
const fullPaddingBase = insets.bottom + insets.top + basePading
const fullPadding = isIOS ? fullPaddingBase : fullPaddingBase + 50
const paddingBottom =
nativeSnapPoint === BottomSheetSnapPoint.Full ? fullPadding : basePading
const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => { const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
if (!isAndroid) { if (!isAndroid) {
@@ -241,14 +204,23 @@ export const ScrollableInner = React.forwardRef<ScrollView, DialogInnerProps>(
} }
} }
const snapPointPadding = {
[BottomSheetSnapPoint.Hidden]: insets.bottom,
[BottomSheetSnapPoint.Partial]: insets.bottom,
[BottomSheetSnapPoint.Full]: insets.bottom + insets.top,
}
return ( return (
<KeyboardAwareScrollView <KeyboardAwareScrollView
style={[style]} style={[style]}
contentContainerStyle={[ contentContainerStyle={[
a.pt_2xl, a.pt_2xl,
a.px_xl, a.px_xl,
{paddingBottom},
contentContainerStyle, contentContainerStyle,
platform({
ios: {paddingBottom: snapPointPadding[nativeSnapPoint] ?? 0},
android: a.pb_2xl,
}),
]} ]}
ref={ref} ref={ref}
{...props} {...props}
@@ -256,6 +228,7 @@ export const ScrollableInner = React.forwardRef<ScrollView, DialogInnerProps>(
bottomOffset={30} bottomOffset={30}
scrollEventThrottle={50} scrollEventThrottle={50}
onScroll={isAndroid ? onScroll : undefined} onScroll={isAndroid ? onScroll : undefined}
keyboardDismissMode="interactive"
keyboardShouldPersistTaps="handled" keyboardShouldPersistTaps="handled"
stickyHeaderIndices={header ? [0] : undefined}> stickyHeaderIndices={header ? [0] : undefined}>
{header} {header}
-13
View File
@@ -1,6 +1,5 @@
import React, {useCallback} from 'react' import React, {useCallback} from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {useKeyboardController} from 'react-native-keyboard-controller'
import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api' import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
@@ -38,18 +37,6 @@ export function MessagesConversationScreen({route}: Props) {
const convoId = route.params.conversation const convoId = route.params.conversation
const {setCurrentConvoId} = useCurrentConvoId() const {setCurrentConvoId} = useCurrentConvoId()
const {setEnabled} = useKeyboardController()
useFocusEffect(
useCallback(() => {
if (isWeb) return
setEnabled(true)
return () => {
setEnabled(false)
}
}, [setEnabled]),
)
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {
setCurrentConvoId(convoId) setCurrentConvoId(convoId)
+2 -8
View File
@@ -1,9 +1,6 @@
import React from 'react' import React from 'react'
import {Keyboard, TouchableOpacity, View} from 'react-native' import {Keyboard, TouchableOpacity, View} from 'react-native'
import { import {KeyboardAwareScrollView} from 'react-native-keyboard-controller'
KeyboardAwareScrollView,
useKeyboardController,
} from 'react-native-keyboard-controller'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import { import {
@@ -151,7 +148,6 @@ function WizardInner({
const {_} = useLingui() const {_} = useLingui()
const t = useTheme() const t = useTheme()
const setMinimalShellMode = useSetMinimalShellMode() const setMinimalShellMode = useSetMinimalShellMode()
const {setEnabled} = useKeyboardController()
const [state, dispatch] = useWizardState() const [state, dispatch] = useWizardState()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const {data: currentProfile} = useProfileQuery({ const {data: currentProfile} = useProfileQuery({
@@ -168,14 +164,12 @@ function WizardInner({
useFocusEffect( useFocusEffect(
React.useCallback(() => { React.useCallback(() => {
setEnabled(true)
setMinimalShellMode(true) setMinimalShellMode(true)
return () => { return () => {
setMinimalShellMode(false) setMinimalShellMode(false)
setEnabled(false)
} }
}, [setMinimalShellMode, setEnabled]), }, [setMinimalShellMode]),
) )
const getDefaultName = () => { const getDefaultName = () => {