@planningcenter/chat-react-native 3.42.1-qa-staging.2 → 3.42.1-qa-staging.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/display/keyboard_view.d.ts +1 -0
- package/build/components/display/keyboard_view.d.ts.map +1 -1
- package/build/components/display/keyboard_view.js +23 -4
- package/build/components/display/keyboard_view.js.map +1 -1
- package/build/components/display/text_input.d.ts.map +1 -1
- package/build/components/display/text_input.js +5 -4
- package/build/components/display/text_input.js.map +1 -1
- package/package.json +3 -3
- package/src/components/display/keyboard_view.tsx +34 -9
- package/src/components/display/text_input.tsx +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ViewProps } from 'react-native';
|
|
3
|
+
export declare const useKeyboardViewReady: () => boolean;
|
|
3
4
|
export declare function KeyboardView({ children }: Pick<ViewProps, 'children'>): React.JSX.Element;
|
|
4
5
|
export declare const useKeyboardOpen: () => boolean;
|
|
5
6
|
//# sourceMappingURL=keyboard_view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard_view.d.ts","sourceRoot":"","sources":["../../../src/components/display/keyboard_view.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyboard_view.d.ts","sourceRoot":"","sources":["../../../src/components/display/keyboard_view.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAyD,MAAM,OAAO,CAAA;AAC7E,OAAO,EAOL,SAAS,EACV,MAAM,cAAc,CAAA;AAOrB,eAAO,MAAM,oBAAoB,eAA6C,CAAA;AAE9E,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,qBAkCrE;AAiBD,eAAO,MAAM,eAAe,eAgB3B,CAAA"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useNavigation } from '@react-navigation/native';
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
3
|
import { Dimensions, Keyboard, KeyboardAvoidingView, Platform, StyleSheet, View, } from 'react-native';
|
|
3
4
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
5
|
import { useChatContext } from '../../contexts/chat_context';
|
|
6
|
+
// Default true: outside a KeyboardView there's no measurement to wait for.
|
|
7
|
+
const KeyboardViewReadyContext = createContext(true);
|
|
8
|
+
export const useKeyboardViewReady = () => useContext(KeyboardViewReadyContext);
|
|
5
9
|
export function KeyboardView({ children }) {
|
|
6
10
|
const styles = useStyles();
|
|
7
11
|
const isKeyboardOpen = useKeyboardOpen();
|
|
8
12
|
const screenHeight = Dimensions.get('screen').height;
|
|
9
13
|
const [pageSheetGap, setPageSheetGap] = useState(0);
|
|
14
|
+
const hasTransitionedIn = useHasTransitionedIn();
|
|
10
15
|
const { bottom } = useSafeAreaInsets();
|
|
11
16
|
const { edgeToEdge } = useChatContext();
|
|
12
17
|
const behavior = Platform.select({
|
|
@@ -17,11 +22,25 @@ export function KeyboardView({ children }) {
|
|
|
17
22
|
const { height: viewHeight } = event.nativeEvent.layout;
|
|
18
23
|
setPageSheetGap(screenHeight - viewHeight);
|
|
19
24
|
}}>
|
|
20
|
-
<
|
|
21
|
-
{
|
|
22
|
-
|
|
25
|
+
<KeyboardViewReadyContext.Provider value={hasTransitionedIn}>
|
|
26
|
+
<KeyboardAvoidingView keyboardVerticalOffset={pageSheetGap - bottom} behavior={behavior} style={styles.keyboardView} enabled={Platform.select({ android: isKeyboardOpen, ios: true })}>
|
|
27
|
+
{children}
|
|
28
|
+
</KeyboardAvoidingView>
|
|
29
|
+
</KeyboardViewReadyContext.Provider>
|
|
23
30
|
</View>);
|
|
24
31
|
}
|
|
32
|
+
const useHasTransitionedIn = () => {
|
|
33
|
+
const navigation = useNavigation();
|
|
34
|
+
const [hasTransitionedIn, setHasTransitionedIn] = useState(false);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
return navigation.addListener('transitionEnd', event => {
|
|
37
|
+
if (event.data.closing)
|
|
38
|
+
return;
|
|
39
|
+
setHasTransitionedIn(true);
|
|
40
|
+
});
|
|
41
|
+
}, [navigation]);
|
|
42
|
+
return hasTransitionedIn;
|
|
43
|
+
};
|
|
25
44
|
export const useKeyboardOpen = () => {
|
|
26
45
|
const [open, setOpen] = useState(false);
|
|
27
46
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard_view.js","sourceRoot":"","sources":["../../../src/components/display/keyboard_view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"keyboard_view.js","sourceRoot":"","sources":["../../../src/components/display/keyboard_view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAEvE,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7E,OAAO,EACL,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACV,IAAI,GAEL,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,2EAA2E;AAC3E,MAAM,wBAAwB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;AAEpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;AAE9E,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAA+B;IACpE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,cAAc,GAAG,eAAe,EAAE,CAAA;IACxC,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAA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ent":["import { ParamListBase, useNavigation } from '@react-navigation/native'\nimport type { NativeStackNavigationProp } from '@react-navigation/native-stack'\nimport React, { createContext, useContext, useEffect, useState } from 'react'\nimport {\n Dimensions,\n Keyboard,\n KeyboardAvoidingView,\n Platform,\n StyleSheet,\n View,\n ViewProps,\n} from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { useChatContext } from '../../contexts/chat_context'\n\n// Default true: outside a KeyboardView there's no measurement to wait for.\nconst KeyboardViewReadyContext = createContext(true)\n\nexport const useKeyboardViewReady = () => useContext(KeyboardViewReadyContext)\n\nexport function KeyboardView({ children }: Pick<ViewProps, 'children'>) {\n const styles = useStyles()\n const isKeyboardOpen = useKeyboardOpen()\n const screenHeight = Dimensions.get('screen').height\n const [pageSheetGap, setPageSheetGap] = useState<number>(0)\n const hasTransitionedIn = useHasTransitionedIn()\n const { bottom } = useSafeAreaInsets()\n const { edgeToEdge } = useChatContext()\n\n const behavior: 'padding' | 'height' | 'position' | undefined = Platform.select({\n android: edgeToEdge ? 'padding' : undefined,\n ios: 'padding',\n })\n\n return (\n <View\n style={styles.pageGapView}\n onLayout={event => {\n const { height: viewHeight } = event.nativeEvent.layout\n setPageSheetGap(screenHeight - viewHeight)\n }}\n >\n <KeyboardViewReadyContext.Provider value={hasTransitionedIn}>\n <KeyboardAvoidingView\n keyboardVerticalOffset={pageSheetGap - bottom}\n behavior={behavior}\n style={styles.keyboardView}\n enabled={Platform.select({ android: isKeyboardOpen, ios: true })}\n >\n {children}\n </KeyboardAvoidingView>\n </KeyboardViewReadyContext.Provider>\n </View>\n )\n}\n\nconst useHasTransitionedIn = () => {\n const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>()\n const [hasTransitionedIn, setHasTransitionedIn] = useState<boolean>(false)\n\n useEffect(() => {\n return navigation.addListener('transitionEnd', event => {\n if (event.data.closing) return\n\n setHasTransitionedIn(true)\n })\n }, [navigation])\n\n return hasTransitionedIn\n}\n\nexport const useKeyboardOpen = () => {\n const [open, setOpen] = useState(false)\n\n useEffect(() => {\n return Keyboard.addListener('keyboardDidShow', () => {\n setOpen(true)\n }).remove\n }, [])\n\n useEffect(() => {\n return Keyboard.addListener('keyboardDidHide', () => {\n setOpen(false)\n }).remove\n }, [])\n\n return open\n}\n\nconst useStyles = () => {\n return StyleSheet.create({\n pageGapView: {\n flex: 1,\n },\n keyboardView: {\n flex: 1,\n },\n })\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text_input.d.ts","sourceRoot":"","sources":["../../../src/components/display/text_input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"text_input.d.ts","sourceRoot":"","sources":["../../../src/components/display/text_input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAGxD,UAAU,4BAA6B,SAAQ,cAAc;IAC3D,QAAQ,CAAC,EAAE,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;CACvC;AAED,eAAO,MAAM,uBAAuB,GAAI,OAAO,4BAA4B,gCAe1E,CAAA"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { TextInput } from 'react-native';
|
|
3
|
-
|
|
3
|
+
import { useKeyboardViewReady } from './keyboard_view';
|
|
4
4
|
export const AutoFocusAwareTextInput = (props) => {
|
|
5
5
|
const { inputRef } = props;
|
|
6
6
|
const defaultRef = useRef(null);
|
|
7
7
|
const ref = inputRef || defaultRef;
|
|
8
|
+
const keyboardViewReady = useKeyboardViewReady();
|
|
8
9
|
const autoFocus = props.autoFocus;
|
|
9
10
|
useEffect(() => {
|
|
10
|
-
if (!autoFocus)
|
|
11
|
+
if (!autoFocus || !keyboardViewReady)
|
|
11
12
|
return;
|
|
12
|
-
|
|
13
|
-
}, [ref, autoFocus]);
|
|
13
|
+
ref?.current?.focus();
|
|
14
|
+
}, [ref, autoFocus, keyboardViewReady]);
|
|
14
15
|
return <TextInput ref={ref} {...props} autoFocus={false}/>;
|
|
15
16
|
};
|
|
16
17
|
//# sourceMappingURL=text_input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text_input.js","sourceRoot":"","sources":["../../../src/components/display/text_input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAkB,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"text_input.js","sourceRoot":"","sources":["../../../src/components/display/text_input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAkB,SAAS,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAMtD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmC,EAAE,EAAE;IAC7E,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAY,IAAI,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,QAAQ,IAAI,UAAU,CAAA;IAClC,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAA;IAEhD,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;IAEjC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS,IAAI,CAAC,iBAAiB;YAAE,OAAM;QAE5C,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IACvB,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAEvC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EAAG,CAAA;AAC7D,CAAC,CAAA","sourcesContent":["import { RefObject, useEffect, useRef } from 'react'\nimport { TextInputProps, TextInput } from 'react-native'\nimport { useKeyboardViewReady } from './keyboard_view'\n\ninterface AutoFocusAwareTextInputProps extends TextInputProps {\n inputRef?: RefObject<TextInput | null>\n}\n\nexport const AutoFocusAwareTextInput = (props: AutoFocusAwareTextInputProps) => {\n const { inputRef } = props\n const defaultRef = useRef<TextInput>(null)\n const ref = inputRef || defaultRef\n const keyboardViewReady = useKeyboardViewReady()\n\n const autoFocus = props.autoFocus\n\n useEffect(() => {\n if (!autoFocus || !keyboardViewReady) return\n\n ref?.current?.focus()\n }, [ref, autoFocus, keyboardViewReady])\n\n return <TextInput ref={ref} {...props} autoFocus={false} />\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "3.42.1-qa-staging.
|
|
3
|
+
"version": "3.42.1-qa-staging.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"react-native": "./src/index.tsx",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
28
28
|
"@fortawesome/react-native-fontawesome": "^0.3.2",
|
|
29
|
-
"@planningcenter/emoji-keyboard": "3.42.1-qa-staging.
|
|
29
|
+
"@planningcenter/emoji-keyboard": "3.42.1-qa-staging.4",
|
|
30
30
|
"lodash-inflection": "^1.5.0",
|
|
31
31
|
"react-compiler-runtime": "^1.0.0"
|
|
32
32
|
},
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"react-native-url-polyfill": "^2.0.0",
|
|
73
73
|
"typescript": "~5.9.2"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "e086a562b612ce019f7ff9b43cceaceb0f2ee86e"
|
|
76
76
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ParamListBase, useNavigation } from '@react-navigation/native'
|
|
2
|
+
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState } from 'react'
|
|
2
4
|
import {
|
|
3
5
|
Dimensions,
|
|
4
6
|
Keyboard,
|
|
@@ -11,11 +13,17 @@ import {
|
|
|
11
13
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
12
14
|
import { useChatContext } from '../../contexts/chat_context'
|
|
13
15
|
|
|
16
|
+
// Default true: outside a KeyboardView there's no measurement to wait for.
|
|
17
|
+
const KeyboardViewReadyContext = createContext(true)
|
|
18
|
+
|
|
19
|
+
export const useKeyboardViewReady = () => useContext(KeyboardViewReadyContext)
|
|
20
|
+
|
|
14
21
|
export function KeyboardView({ children }: Pick<ViewProps, 'children'>) {
|
|
15
22
|
const styles = useStyles()
|
|
16
23
|
const isKeyboardOpen = useKeyboardOpen()
|
|
17
24
|
const screenHeight = Dimensions.get('screen').height
|
|
18
25
|
const [pageSheetGap, setPageSheetGap] = useState<number>(0)
|
|
26
|
+
const hasTransitionedIn = useHasTransitionedIn()
|
|
19
27
|
const { bottom } = useSafeAreaInsets()
|
|
20
28
|
const { edgeToEdge } = useChatContext()
|
|
21
29
|
|
|
@@ -32,18 +40,35 @@ export function KeyboardView({ children }: Pick<ViewProps, 'children'>) {
|
|
|
32
40
|
setPageSheetGap(screenHeight - viewHeight)
|
|
33
41
|
}}
|
|
34
42
|
>
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
<KeyboardViewReadyContext.Provider value={hasTransitionedIn}>
|
|
44
|
+
<KeyboardAvoidingView
|
|
45
|
+
keyboardVerticalOffset={pageSheetGap - bottom}
|
|
46
|
+
behavior={behavior}
|
|
47
|
+
style={styles.keyboardView}
|
|
48
|
+
enabled={Platform.select({ android: isKeyboardOpen, ios: true })}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</KeyboardAvoidingView>
|
|
52
|
+
</KeyboardViewReadyContext.Provider>
|
|
43
53
|
</View>
|
|
44
54
|
)
|
|
45
55
|
}
|
|
46
56
|
|
|
57
|
+
const useHasTransitionedIn = () => {
|
|
58
|
+
const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>()
|
|
59
|
+
const [hasTransitionedIn, setHasTransitionedIn] = useState<boolean>(false)
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return navigation.addListener('transitionEnd', event => {
|
|
63
|
+
if (event.data.closing) return
|
|
64
|
+
|
|
65
|
+
setHasTransitionedIn(true)
|
|
66
|
+
})
|
|
67
|
+
}, [navigation])
|
|
68
|
+
|
|
69
|
+
return hasTransitionedIn
|
|
70
|
+
}
|
|
71
|
+
|
|
47
72
|
export const useKeyboardOpen = () => {
|
|
48
73
|
const [open, setOpen] = useState(false)
|
|
49
74
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { RefObject, useEffect, useRef } from 'react'
|
|
2
2
|
import { TextInputProps, TextInput } from 'react-native'
|
|
3
|
+
import { useKeyboardViewReady } from './keyboard_view'
|
|
3
4
|
|
|
4
5
|
interface AutoFocusAwareTextInputProps extends TextInputProps {
|
|
5
6
|
inputRef?: RefObject<TextInput | null>
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
const TIMEOUT = 500
|
|
9
|
-
|
|
10
9
|
export const AutoFocusAwareTextInput = (props: AutoFocusAwareTextInputProps) => {
|
|
11
10
|
const { inputRef } = props
|
|
12
11
|
const defaultRef = useRef<TextInput>(null)
|
|
13
12
|
const ref = inputRef || defaultRef
|
|
13
|
+
const keyboardViewReady = useKeyboardViewReady()
|
|
14
14
|
|
|
15
15
|
const autoFocus = props.autoFocus
|
|
16
16
|
|
|
17
17
|
useEffect(() => {
|
|
18
|
-
if (!autoFocus) return
|
|
18
|
+
if (!autoFocus || !keyboardViewReady) return
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
}, [ref, autoFocus])
|
|
20
|
+
ref?.current?.focus()
|
|
21
|
+
}, [ref, autoFocus, keyboardViewReady])
|
|
22
22
|
|
|
23
23
|
return <TextInput ref={ref} {...props} autoFocus={false} />
|
|
24
24
|
}
|