-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathVirtualizedListScrollView.tsx
More file actions
92 lines (82 loc) · 2.43 KB
/
VirtualizedListScrollView.tsx
File metadata and controls
92 lines (82 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { forwardRef, useCallback, useState } from "react";
import {
type LayoutChangeEvent,
type ScrollViewProps,
StyleSheet,
Text,
} from "react-native";
import {
KeyboardChatScrollView,
KeyboardController,
} from "react-native-keyboard-controller";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useChatConfigStore } from "./store";
import {
MARGIN,
contentContainerStyle,
invertedContentContainerStyle,
} from "./styles";
import type { SharedValue } from "react-native-reanimated";
type VirtualizedListScrollViewProps = ScrollViewProps & {
extraContentPadding?: SharedValue<number>;
};
export type VirtualizedListScrollViewRef = React.ElementRef<
typeof KeyboardChatScrollView
>;
const VirtualizedListScrollView = forwardRef<
VirtualizedListScrollViewRef,
VirtualizedListScrollViewProps
>(({ onLayout: onLayoutProp, extraContentPadding, ...props }, ref) => {
const [layoutPass, setLayoutPass] = useState(0);
const { bottom } = useSafeAreaInsets();
const chatKitOffset = bottom - MARGIN;
const { inverted, freeze, mode, keyboardLiftBehavior } = useChatConfigStore();
// on old arch only FlatList and FlashList supports `inverted` prop
const isInvertedSupported =
inverted && (mode === "flat" || mode === "flash") ? inverted : false;
const onLayout = useCallback(
(e: LayoutChangeEvent) => {
setLayoutPass((l) => l + 1);
onLayoutProp?.(e);
},
[onLayoutProp],
);
return (
<>
<KeyboardChatScrollView
ref={ref}
automaticallyAdjustContentInsets={false}
contentContainerStyle={
inverted ? invertedContentContainerStyle : contentContainerStyle
}
contentInsetAdjustmentBehavior="never"
extraContentPadding={extraContentPadding}
freeze={freeze}
inverted={isInvertedSupported}
keyboardDismissMode="interactive"
keyboardLiftBehavior={keyboardLiftBehavior}
offset={chatKitOffset}
testID="chat.scroll"
onLayout={onLayout}
{...props}
/>
<Text
style={styles.counter}
testID="layout_passes"
onPress={() => KeyboardController.dismiss()}
>
Layout pass: {layoutPass}
</Text>
</>
);
});
const styles = StyleSheet.create({
counter: {
position: "absolute",
color: "white",
top: 0,
padding: 12,
backgroundColor: "#3c3c3c",
},
});
export default VirtualizedListScrollView;