Skip to content

Commit 15b5b07

Browse files
committed
[connectReactNativeChat] refactor to separate the UI and state logic
1 parent 24e2a66 commit 15b5b07

9 files changed

Lines changed: 1055 additions & 91 deletions

File tree

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,12 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: MIT-0
33

4-
import React from "react";
5-
import { View, Image } from "react-native";
6-
import { createStackNavigator } from "@react-navigation/stack";
7-
import { NavigationContainer } from "@react-navigation/native";
4+
import React from 'react';
5+
import ChatUI from "./src/ChatUI";
86

9-
import ChatWrapper from "./src/components/ChatWrapper";
10-
import GiftedChatWidget from "./src/components/ChatWidget";
11-
import DebuggerWidget from "./src/components/DebuggerWidget";
12-
import ChatForm from "./src/components/ChatForm";
13-
14-
import { LogBox } from "react-native";
15-
import { ENABLE_REACTNATIVE_LOGBOX } from "./config";
16-
if (!ENABLE_REACTNATIVE_LOGBOX) {
17-
LogBox.ignoreAllLogs();
7+
export default function App() {
8+
return <ChatUI />;
189
}
1910

20-
const ChatScreen = ({ navigation }) => {
21-
return (
22-
<ChatWrapper
23-
navigation={navigation}
24-
ChatWidgetComponent={GiftedChatWidget}
25-
/>
26-
);
27-
};
28-
29-
const HomeScreen = ({ navigation }) => (
30-
<View
31-
style={{
32-
flex: 1,
33-
alignItems: "center",
34-
padding: 10,
35-
marginTop: 100,
36-
}}
37-
>
38-
<Image
39-
source={require("./assets/connect.png")}
40-
style={{
41-
height: 90,
42-
width: 100,
43-
padding: 10,
44-
}}
45-
alt="Connect logo"
46-
/>
47-
48-
<ChatForm openChatScreen={() => navigation.navigate("Chat")} />
49-
50-
<DebuggerWidget />
51-
</View>
52-
);
53-
54-
const Stack = createStackNavigator();
55-
56-
const App = () => {
57-
return (
58-
<NavigationContainer>
59-
<Stack.Navigator initialRouteName="Home">
60-
<Stack.Screen name="Home" component={HomeScreen} />
61-
<Stack.Screen name="Chat" component={ChatScreen} />
62-
</Stack.Navigator>
63-
</NavigationContainer>
64-
);
65-
};
66-
67-
export default App;
11+
// import { LogBox } from "react-native";
12+
// LogBox.ignoreAllLogs(); // DISABLE_REACTNATIVE_LOGBOX

‎mobileChatExamples/connectReactNativeChat/jest.config.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ module.exports = {
22
testEnvironment: "jsdom",
33
preset: "react-native",
44
transformIgnorePatterns: ["node_modules/(?!react-native-url-polyfill)/"],
5+
setupFiles: ['./jest.setup.js']
56
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
process.env.TZ = 'UTC';
2+
3+
jest.mock('@react-native-community/netinfo', () => ({
4+
getCurrentConnectivity: jest.fn(),
5+
isConnectionMetered: jest.fn(),
6+
addListener: jest.fn(),
7+
removeListeners: jest.fn(),
8+
isConnected: {
9+
fetch: () => Promise.resolve(true),
10+
addEventListener: jest.fn(),
11+
removeEventListener: jest.fn(),
12+
},
13+
}));
14+
15+
jest.mock('@react-native-async-storage/async-storage', () => ({
16+
setItem: jest.fn(() => Promise.resolve()),
17+
getItem: jest.fn(() => Promise.resolve()),
18+
removeItem: jest.fn(() => Promise.resolve()),
19+
clear: jest.fn(() => Promise.resolve()),
20+
getAllKeys: jest.fn(() => Promise.resolve([])),
21+
multiGet: jest.fn(() => Promise.resolve([])),
22+
multiSet: jest.fn(() => Promise.resolve()),
23+
multiRemove: jest.fn(() => Promise.resolve()),
24+
mergeItem: jest.fn(() => Promise.resolve()),
25+
}));

0 commit comments

Comments
 (0)