Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 7bdce4b

Browse files
authored
Merge pull request #1743 from showtime-xyz/feat/improve-keyboard-on-ios
perf: imporve keyboard on iOS
2 parents 073cf48 + da8bbba commit 7bdce4b

File tree

9 files changed

+71
-82
lines changed

9 files changed

+71
-82
lines changed

apps/expo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"@storybook/react-native": "next",
247247
"@types/jest": "^27.4.1",
248248
"@types/qrcode": "^1.5.0",
249-
"@types/react": "18.0.24",
249+
"@types/react": "~18.0.24",
250250
"@types/three": "^0.142.0",
251251
"@types/uuid": "^8.3.4",
252252
"babel-jest": "^28.1.3",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"devDependencies": {
77
"@react-native-menu/menu": "^0.7.2",
88
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
9-
"@types/react-native": "0.69.3",
9+
"@types/react-native": "0.70.5",
1010
"@typescript-eslint/eslint-plugin": "5.23.0",
1111
"@typescript-eslint/parser": "5.23.0",
1212
"@walletconnect/react-native-dapp": "^1.7.8",

packages/app/components/comments/comment-input-box.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { ViewStyle } from "react-native";
44
import { useAlert } from "@showtime-xyz/universal.alert";
55
import { Button } from "@showtime-xyz/universal.button";
66
import { Close } from "@showtime-xyz/universal.icon";
7-
import { useSafeAreaInsets } from "@showtime-xyz/universal.safe-area";
87
import { Text } from "@showtime-xyz/universal.text";
98
import { View } from "@showtime-xyz/universal.view";
109

1110
import { MessageBox } from "app/components/messages/message-box";
1211
import { CommentType } from "app/hooks/api/use-comments";
13-
import { useKeyboardVisible } from "app/hooks/use-keyboard-visible";
1412
import { useUser } from "app/hooks/use-user";
1513
import { formatAddressShort } from "app/utilities";
1614

@@ -34,12 +32,9 @@ export const CommentInputBox = forwardRef<
3432
>(function CommentInputBox({ submitting, submit, commentInputRef }, ref) {
3533
//#region variables
3634
const Alert = useAlert();
37-
const { visible } = useKeyboardVisible();
38-
3935
const [selectedComment, setSelectedComment] = useState<CommentType | null>(
4036
null
4137
);
42-
const { bottom } = useSafeAreaInsets();
4338
const { user } = useUser();
4439
//#endregion
4540

@@ -97,7 +92,7 @@ export const CommentInputBox = forwardRef<
9792
<Button
9893
variant="text"
9994
size="small"
100-
tw="mr--4"
95+
tw="mr-4"
10196
onPress={handleOnClearPress}
10297
>
10398
<Close color={"black"} width={16} height={16} />
@@ -107,11 +102,6 @@ export const CommentInputBox = forwardRef<
107102
<MessageBox
108103
ref={commentInputRef}
109104
submitting={submitting}
110-
style={{
111-
paddingHorizontal: 16,
112-
marginBottom: Math.max(0, bottom - (visible ? 8 : 0)),
113-
paddingBottom: 0,
114-
}}
115105
onSubmit={handleOnSubmitComment}
116106
userAvatar={user?.data.profile.img_url}
117107
/>

packages/app/components/comments/comments-container.ios.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/app/components/comments/comments-container.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/app/components/comments/index.tsx

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import { useCallback, useMemo, useRef, useEffect } from "react";
2-
import { Platform, StyleSheet, TextInput } from "react-native";
1+
import { useCallback, useMemo, useRef, useEffect, Fragment } from "react";
2+
import {
3+
Platform,
4+
StyleSheet,
5+
TextInput,
6+
InputAccessoryView,
7+
} from "react-native";
38

49
import { ListRenderItemInfo } from "@shopify/flash-list";
10+
import { AvoidSoftInput } from "react-native-avoid-softinput";
511

612
import { useAlert } from "@showtime-xyz/universal.alert";
13+
import { useIsDarkMode } from "@showtime-xyz/universal.hooks";
714
import { InfiniteScrollList } from "@showtime-xyz/universal.infinite-scroll-list";
815
import { useSafeAreaInsets } from "@showtime-xyz/universal.safe-area";
16+
import { colors } from "@showtime-xyz/universal.tailwind";
917
import { View } from "@showtime-xyz/universal.view";
1018

1119
import { CommentRow } from "app/components/comments/comment-row";
@@ -16,11 +24,13 @@ import type { NFT } from "app/types";
1624

1725
import { EmptyPlaceholder } from "../empty-placeholder";
1826
import { CommentInputBox, CommentInputBoxMethods } from "./comment-input-box";
19-
import { CommentsContainer } from "./comments-container";
2027
import { CommentsStatus } from "./comments-status";
2128

2229
const keyExtractor = (item: CommentType) => `comment-${item.comment_id}`;
2330

31+
const PlatformInputAccessoryView =
32+
Platform.OS === "ios" ? InputAccessoryView : Fragment;
33+
2434
export function Comments({ nft }: { nft: NFT }) {
2535
//#region refs
2636
const Alert = useAlert();
@@ -32,11 +42,20 @@ export function Comments({ nft }: { nft: NFT }) {
3242

3343
useEffect(() => {
3444
// auto focus on comment modal open on native
45+
if (Platform.OS === "ios") {
46+
AvoidSoftInput.setEnabled(false);
47+
}
48+
3549
if (Platform.OS !== "web") {
3650
setTimeout(() => {
3751
commentInputRef.current?.focus?.();
3852
}, 100);
3953
}
54+
return () => {
55+
if (Platform.OS === "ios") {
56+
AvoidSoftInput.setEnabled(true);
57+
}
58+
};
4059
}, []);
4160

4261
//#region hooks
@@ -53,6 +72,7 @@ export function Comments({ nft }: { nft: NFT }) {
5372
} = useComments(nft.nft_id);
5473
const modalListProps = useModalListProps();
5574
const { bottom } = useSafeAreaInsets();
75+
const isDark = useIsDarkMode();
5676
//#endregion
5777
//#region variables
5878
const dataReversed = useMemo(
@@ -137,7 +157,7 @@ export function Comments({ nft }: { nft: NFT }) {
137157
[bottom]
138158
);
139159
return (
140-
<CommentsContainer style={styles.container}>
160+
<View style={styles.container}>
141161
{isLoading || (dataReversed.length == 0 && error) ? (
142162
<CommentsStatus isLoading={isLoading} error={error} />
143163
) : (
@@ -149,29 +169,42 @@ export function Comments({ nft }: { nft: NFT }) {
149169
keyExtractor={keyExtractor}
150170
estimatedItemSize={98}
151171
overscan={98}
152-
keyboardDismissMode="on-drag"
172+
keyboardDismissMode="interactive"
153173
ListEmptyComponent={listEmptyComponent}
154174
ListFooterComponent={listFooterComponent}
175+
automaticallyAdjustKeyboardInsets
176+
contentInsetAdjustmentBehavior="never"
155177
{...modalListProps}
156178
/>
157179
{isAuthenticated && (
158-
<CommentInputBox
159-
ref={inputRef}
160-
commentInputRef={commentInputRef}
161-
submitting={isSubmitting}
162-
submit={newComment}
163-
/>
180+
<PlatformInputAccessoryView
181+
{...Platform.select({
182+
ios: {
183+
backgroundColor: isDark ? colors.black : colors.white,
184+
},
185+
default: {},
186+
})}
187+
>
188+
<CommentInputBox
189+
ref={inputRef}
190+
commentInputRef={commentInputRef}
191+
submitting={isSubmitting}
192+
submit={newComment}
193+
/>
194+
</PlatformInputAccessoryView>
164195
)}
165196
</>
166197
)}
167-
</CommentsContainer>
198+
</View>
168199
);
169200
//#endregion
170201
}
171202

172203
const styles = StyleSheet.create({
173204
container: {
174205
flex: 1,
206+
// Notes: for `FlashList's rendered size is not usable` warning on Android.
207+
minHeight: 200,
175208
},
176209
contentContainer: {
177210
flex: 1,

packages/app/components/messages/message-box.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ export const MessageBox = forwardRef<MessageBoxMethods, MessageBoxProps>(
7777
[handleReset, handleFocus]
7878
);
7979
return (
80-
<View
81-
tw="flex-row items-center bg-white py-4 dark:bg-black"
82-
style={style}
83-
>
80+
<View tw="flex-row items-center bg-white p-4 dark:bg-black" style={style}>
8481
<View tw="mr-2 flex-1">
8582
<TextInput
8683
//@ts-ignore
@@ -110,7 +107,11 @@ export const MessageBox = forwardRef<MessageBoxMethods, MessageBoxProps>(
110107
onPress={handleSubmit}
111108
style={{ opacity: disable ? 0.4 : 1 }}
112109
>
113-
{submitting ? <Spinner size="small" /> : <Send />}
110+
{submitting ? (
111+
<Spinner size="small" />
112+
) : (
113+
<Send width={24} height={24} />
114+
)}
114115
</Button>
115116
</View>
116117
);

packages/design-system/date-time-picker/date-time-picker.stories.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ export const Basic: React.FC<{}> = () => {
2020
flexDirection: "row",
2121
alignItems: "center",
2222
}}
23-
// @ts-ignore
24-
dataSet={{
25-
"data-chromatic": "ignore",
26-
}}
2723
>
2824
<Pressable
2925
style={{ marginTop: 100 }}
3026
onPress={() => {
3127
setOpen(!open);
3228
}}
3329
>
34-
<Text>Date {date.toString()}</Text>
30+
<Text
31+
dataSet={{
32+
"data-chromatic": "ignore",
33+
}}
34+
>
35+
Date {date.toString()}
36+
</Text>
3537
</Pressable>
3638

3739
<DateTimePicker
@@ -40,6 +42,10 @@ export const Basic: React.FC<{}> = () => {
4042
setOpen(false);
4143
setDate(d);
4244
}}
45+
// @ts-ignore
46+
dataSet={{
47+
"data-chromatic": "ignore",
48+
}}
4349
value={date}
4450
open={open}
4551
/>

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8879,7 +8879,7 @@ __metadata:
88798879
"@tradle/react-native-http": ^2.0.1
88808880
"@types/jest": ^27.4.1
88818881
"@types/qrcode": ^1.5.0
8882-
"@types/react": 18.0.24
8882+
"@types/react": ~18.0.24
88838883
"@types/three": ^0.142.0
88848884
"@types/uuid": ^8.3.4
88858885
"@walletconnect/react-native-dapp": ^1.8.0
@@ -11684,12 +11684,12 @@ __metadata:
1168411684
languageName: node
1168511685
linkType: hard
1168611686

11687-
"@types/react-native@npm:0.69.3":
11688-
version: 0.69.3
11689-
resolution: "@types/react-native@npm:0.69.3"
11687+
"@types/react-native@npm:0.70.5":
11688+
version: 0.70.5
11689+
resolution: "@types/react-native@npm:0.70.5"
1169011690
dependencies:
1169111691
"@types/react": "*"
11692-
checksum: 7d5aa4b30385e232fed74bdebeba1c7ee73b4237ca5a310fee6f9b98432ed2f3a737f2755c528fd5b03485278e98bd0b152692df5e146cb2603827ab939841dc
11692+
checksum: 1a21cd62afcd23cbd2d8e27c3b7601819739bb822e77ce9a3995af14be88e4ae19e467bc4b9c133f6da82648e8a951f07d1e55997d1a7a50260b79c784c24535
1169311693
languageName: node
1169411694
linkType: hard
1169511695

@@ -33243,7 +33243,7 @@ __metadata:
3324333243
"@react-native-menu/menu": ^0.7.2
3324433244
"@trivago/prettier-plugin-sort-imports": ^3.3.0
3324533245
"@types/react-dropzone": ^5.1.0
33246-
"@types/react-native": 0.69.3
33246+
"@types/react-native": 0.70.5
3324733247
"@typescript-eslint/eslint-plugin": 5.23.0
3324833248
"@typescript-eslint/parser": 5.23.0
3324933249
"@walletconnect/react-native-dapp": ^1.7.8

0 commit comments

Comments
 (0)