Skip to content

Commit 3296d4f

Browse files
authored
chore: Enable New Architecture (#6478)
1 parent b4156a3 commit 3296d4f

30 files changed

+819
-426
lines changed

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
3232
# your application. You should enable this flag either if you want
3333
# to write custom TurboModules/Fabric components OR use libraries that
3434
# are providing them.
35-
newArchEnabled=false
35+
newArchEnabled=true
3636

3737
# Application ID
3838
APPLICATION_ID=chat.rocket.reactnative

app/containers/MessageComposer/MessageComposer.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ const initialStoreState = () => {
4343
};
4444
initialStoreState();
4545

46+
jest.mock('./hooks/useSubscription', () => ({
47+
useSubscription: jest.fn(() => ({
48+
rid: 'rid',
49+
t: 'd',
50+
name: 'Room Name',
51+
fname: 'Room Name',
52+
usernames: ['user1', 'user2'],
53+
prid: undefined,
54+
federated: false
55+
}))
56+
}));
57+
4658
const initialContext = {
4759
rid: 'rid',
4860
tmid: undefined,

app/containers/MessageComposer/components/ComposerInput.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const ComposerInput = memo(
4343
const { setFocused, setMicOrSend, setAutocompleteParams } = useMessageComposerApi();
4444
const autocompleteType = useAutocompleteParams()?.type;
4545
const textRef = React.useRef('');
46-
const firstRender = React.useRef(false);
46+
const firstRender = React.useRef(true);
4747
const selectionRef = React.useRef<IInputSelection>(defaultSelection);
4848
const dispatch = useDispatch();
4949
const subscription = useSubscription(rid);
@@ -77,13 +77,13 @@ export const ComposerInput = memo(
7777
}
7878
};
7979

80-
if (sharing) return;
81-
if (usedCannedResponse) setInput(usedCannedResponse);
82-
if (action !== 'edit' && !firstRender.current) {
83-
firstRender.current = true;
80+
if (action !== 'edit' && firstRender.current) {
81+
firstRender.current = false;
8482
setDraftMessage();
8583
}
86-
}, [action, rid, tmid, usedCannedResponse, firstRender.current]);
84+
if (sharing) return;
85+
if (usedCannedResponse) setInput(usedCannedResponse);
86+
}, [action, rid, tmid, usedCannedResponse]);
8787

8888
// Edit/quote
8989
useEffect(() => {

app/containers/MessageComposer/context.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { createContext, ReactElement, useContext, useMemo, useReducer } f
22

33
import { IEmoji } from '../../definitions';
44
import { IAutocompleteBase, TMicOrSend } from './interfaces';
5-
import { animateNextTransition } from '../../lib/methods/helpers';
65

76
type TMessageComposerContextApi = {
87
setFocused(focused: boolean): void;
@@ -66,17 +65,14 @@ type Actions =
6665
const reducer = (state: State, action: Actions): State => {
6766
switch (action.type) {
6867
case 'updateFocused':
69-
animateNextTransition();
7068
return { ...state, focused: action.focused };
7169
case 'setMicOrSend':
7270
return { ...state, micOrSend: action.micOrSend };
7371
case 'setMarkdownToolbar':
74-
animateNextTransition();
7572
return { ...state, showMarkdownToolbar: action.showMarkdownToolbar };
7673
case 'setAlsoSendThreadToChannel':
7774
return { ...state, alsoSendThreadToChannel: action.alsoSendThreadToChannel };
7875
case 'setRecordingAudio':
79-
animateNextTransition();
8076
return { ...state, recordingAudio: action.recordingAudio };
8177
case 'setAutocompleteParams':
8278
return { ...state, autocompleteParams: action.params };

app/containers/MessageComposer/hooks/useAutoSaveDraft.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ export const useAutoSaveDraft = (text = '') => {
3030
saveDraftMessage({ rid, tmid, draftMessage });
3131
}
3232
},
33-
[action, rid, tmid, text, selectedMessages?.length, route.name]
33+
[action, rid, tmid, text, selectedMessages, route.name]
3434
);
3535

3636
// if focused on composer input, saves every N seconds
3737
useEffect(() => {
3838
if (focused) {
3939
intervalRef.current = setInterval(saveMessageDraft, 3000) as any;
4040
} else if (intervalRef.current) {
41+
saveMessageDraft();
4142
clearInterval(intervalRef.current);
4243
}
4344

app/containers/message/Components/Attachments/Image/Image.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useContext, useEffect, useState } from 'react';
2-
import { View, ViewStyle, Image } from 'react-native';
3-
import { Image as ExpoImage } from 'expo-image';
2+
import { View, ViewStyle } from 'react-native';
3+
import { Image } from 'expo-image';
44

55
import { isValidUrl } from '../../../../../lib/methods/helpers/isValidUrl';
66
import { useTheme } from '../../../../../theme';
@@ -11,6 +11,7 @@ import { WidthAwareContext } from '../../WidthAwareView';
1111
import { useUserPreferences } from '../../../../../lib/methods';
1212
import { AUTOPLAY_GIFS_PREFERENCES_KEY } from '../../../../../lib/constants';
1313
import ImageBadge from './ImageBadge';
14+
import log from '../../../../../lib/methods/helpers/log';
1415

1516
export const MessageImage = React.memo(({ uri, status, encrypted = false, imagePreview, imageType }: IMessageImage) => {
1617
const { colors } = useTheme();
@@ -22,8 +23,12 @@ export const MessageImage = React.memo(({ uri, status, encrypted = false, imageP
2223

2324
useEffect(() => {
2425
if (status === 'downloaded') {
25-
Image.getSize(uri, (width, height) => {
26-
setImageDimensions({ width, height });
26+
Image.loadAsync(uri, {
27+
onError: e => {
28+
log(e);
29+
}
30+
}).then(image => {
31+
setImageDimensions({ width: image.width, height: image.height });
2732
});
2833
}
2934
}, [uri, status]);
@@ -62,13 +67,13 @@ export const MessageImage = React.memo(({ uri, status, encrypted = false, imageP
6267
<>
6368
{showImage ? (
6469
<View style={[containerStyle, borderStyle]}>
65-
<ExpoImage autoplay={autoplayGifs} style={imageStyle} source={{ uri: encodeURI(uri) }} contentFit='cover' />
70+
<Image autoplay={autoplayGifs} style={imageStyle} source={{ uri: encodeURI(uri) }} contentFit='cover' />
6671
</View>
6772
) : null}
6873
{['loading', 'to-download'].includes(status) || (status === 'downloaded' && !showImage) ? (
6974
<>
7075
{imagePreview && imageType && !encrypted ? (
71-
<ExpoImage
76+
<Image
7277
autoplay={autoplayGifs}
7378
style={styles.image}
7479
source={{ uri: `data:${imageType};base64,${imagePreview}` }}

app/containers/message/Urls.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ReactElement, useContext, useEffect, useState } from 'react';
2-
import { Image, StyleSheet, Text, View, ViewStyle } from 'react-native';
2+
import { StyleSheet, Text, View, ViewStyle } from 'react-native';
33
import Clipboard from '@react-native-clipboard/clipboard';
4-
import { Image as ExpoImage } from 'expo-image';
4+
import { Image } from 'expo-image';
55
import { dequal } from 'dequal';
66
import axios from 'axios';
77

@@ -72,15 +72,13 @@ const UrlImage = ({ image, hasContent }: { image: string; hasContent: boolean })
7272

7373
useEffect(() => {
7474
if (image) {
75-
Image.getSize(
76-
image,
77-
(width, height) => {
78-
setImageDimensions({ width, height });
79-
},
80-
() => {
75+
Image.loadAsync(image, {
76+
onError: () => {
8177
setImageLoadedState('error');
8278
}
83-
);
79+
}).then(image => {
80+
setImageDimensions({ width: image.width, height: image.height });
81+
});
8482
}
8583
}, [image]);
8684

@@ -113,7 +111,7 @@ const UrlImage = ({ image, hasContent }: { image: string; hasContent: boolean })
113111

114112
return (
115113
<View style={containerStyle}>
116-
<ExpoImage
114+
<Image
117115
source={{ uri: image }}
118116
style={[imageStyle, imageLoadedState === 'loading' && styles.loading]}
119117
contentFit='contain'

app/lib/methods/helpers/layoutAnimation.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import { LayoutAnimation } from 'react-native';
22

33
import { debounce } from './debounce';
4-
import { isIOS } from './deviceInfo';
54

65
export const animateNextTransition = debounce(
76
() => {
8-
if (isIOS) {
9-
LayoutAnimation.configureNext({
10-
duration: 200,
11-
create: {
12-
type: LayoutAnimation.Types.easeInEaseOut,
13-
property: LayoutAnimation.Properties.opacity
14-
},
15-
update: {
16-
type: LayoutAnimation.Types.easeInEaseOut
17-
},
18-
delete: {
19-
type: LayoutAnimation.Types.easeInEaseOut,
20-
property: LayoutAnimation.Properties.opacity
21-
}
22-
});
23-
}
7+
LayoutAnimation.configureNext({
8+
duration: 200,
9+
create: {
10+
type: LayoutAnimation.Types.easeInEaseOut,
11+
property: LayoutAnimation.Properties.opacity
12+
},
13+
update: {
14+
type: LayoutAnimation.Types.easeInEaseOut
15+
},
16+
delete: {
17+
type: LayoutAnimation.Types.easeInEaseOut,
18+
property: LayoutAnimation.Properties.opacity
19+
}
20+
});
2421
},
2522
200,
2623
true

app/views/DirectoryView/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ class DirectoryView extends React.Component<IDirectoryViewProps, IDirectoryViewS
106106
this.setState({ loading: true });
107107

108108
try {
109-
const { data, type, globalUsers } = this.state;
109+
const { type, globalUsers } = this.state;
110+
let { data } = this.state;
111+
// TODO: workaround to fix Fabric batch behavior. It should be fixed when we migrate to function components
112+
if (newSearch) {
113+
data = [];
114+
}
110115
const directories = await Services.getDirectory({
111116
text,
112117
type,
@@ -116,11 +121,11 @@ class DirectoryView extends React.Component<IDirectoryViewProps, IDirectoryViewS
116121
sort: type === 'users' ? { username: 1 } : { usersCount: -1 }
117122
});
118123
if (directories.success) {
119-
this.setState({
120-
data: [...data, ...(directories.result as IServerRoom[])],
124+
this.setState(prev => ({
125+
data: [...prev.data, ...(directories.result as IServerRoom[])],
121126
loading: false,
122127
total: directories.total
123-
});
128+
}));
124129
} else {
125130
this.setState({ loading: false });
126131
}

app/views/RoomView/List/components/NavBottomFAB.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ const NavBottomFAB = memo(({ visible, onPress }: { visible: boolean; onPress: Fu
3434
}
3535

3636
return (
37-
<View style={styles.container} testID='nav-jump-to-bottom'>
37+
<View style={styles.container}>
3838
<Touch
3939
accessible
4040
accessibilityLabel={i18n.t('Jump_to_last_message')}
4141
onPress={() => onPress()}
42-
style={[styles.button, { backgroundColor: colors.surfaceRoom }]}>
42+
style={[styles.button, { backgroundColor: colors.surfaceRoom }]}
43+
testID='nav-jump-to-bottom'>
4344
<View style={[styles.content, { borderColor: colors.strokeLight }]}>
4445
<CustomIcon name='chevron-down' size={36} />
4546
</View>

0 commit comments

Comments
 (0)