react-native-srschat 0.1.0 → 0.1.2
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/dist/commonjs/index.js +163 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/module/index.js +155 -0
- package/dist/module/index.js.map +1 -0
- package/dist/typescript/index.d.ts +13 -0
- package/dist/typescript/index.d.ts.map +1 -0
- package/package.json +61 -172
- package/src/index.tsx +189 -4
- package/README.md +0 -33
- package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -36
- package/android/generated/android/app/build/generated/source/codegen/jni/RNSrschatSpec-generated.cpp +0 -22
- package/android/generated/android/app/build/generated/source/codegen/jni/RNSrschatSpec.h +0 -24
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNSrschatSpec/RNSrschatSpecJSI-generated.cpp +0 -17
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNSrschatSpec/RNSrschatSpecJSI.h +0 -19
- package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm +0 -2321
- package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec.h +0 -2761
- package/ios/generated/build/generated/ios/FBReactNativeSpecJSI-generated.cpp +0 -2923
- package/ios/generated/build/generated/ios/FBReactNativeSpecJSI.h +0 -7718
- package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.h +0 -18
- package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.mm +0 -33
- package/ios/generated/build/generated/ios/RNSrschatSpec/RNSrschatSpec-generated.mm +0 -16
- package/ios/generated/build/generated/ios/RNSrschatSpec/RNSrschatSpec.h +0 -35
- package/ios/generated/build/generated/ios/RNSrschatSpecJSI-generated.cpp +0 -17
- package/ios/generated/build/generated/ios/RNSrschatSpecJSI.h +0 -19
- package/lib/commonjs/components/Chat.js +0 -43
- package/lib/commonjs/components/Chat.js.map +0 -1
- package/lib/commonjs/components/ChatInput.js +0 -64
- package/lib/commonjs/components/ChatInput.js.map +0 -1
- package/lib/commonjs/components/ChatMessage.js +0 -58
- package/lib/commonjs/components/ChatMessage.js.map +0 -1
- package/lib/commonjs/index.js +0 -37
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/components/Chat.js +0 -39
- package/lib/module/components/Chat.js.map +0 -1
- package/lib/module/components/ChatInput.js +0 -60
- package/lib/module/components/ChatInput.js.map +0 -1
- package/lib/module/components/ChatMessage.js +0 -54
- package/lib/module/components/ChatMessage.js.map +0 -1
- package/lib/module/index.js +0 -8
- package/lib/module/index.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/components/Chat.d.ts +0 -3
- package/lib/typescript/commonjs/src/components/Chat.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/ChatInput.d.ts +0 -6
- package/lib/typescript/commonjs/src/components/ChatInput.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/ChatMessage.d.ts +0 -8
- package/lib/typescript/commonjs/src/components/ChatMessage.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -4
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types.d.ts +0 -12
- package/lib/typescript/commonjs/src/types.d.ts.map +0 -1
- package/lib/typescript/module/package.json +0 -1
- package/lib/typescript/module/src/components/Chat.d.ts +0 -3
- package/lib/typescript/module/src/components/Chat.d.ts.map +0 -1
- package/lib/typescript/module/src/components/ChatInput.d.ts +0 -6
- package/lib/typescript/module/src/components/ChatInput.d.ts.map +0 -1
- package/lib/typescript/module/src/components/ChatMessage.d.ts +0 -8
- package/lib/typescript/module/src/components/ChatMessage.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -4
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- package/lib/typescript/module/src/types.d.ts +0 -12
- package/lib/typescript/module/src/types.d.ts.map +0 -1
- package/src/components/Chat.tsx +0 -34
- package/src/components/ChatInput.tsx +0 -58
- package/src/components/ChatMessage.tsx +0 -51
- package/src/types.ts +0 -12
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
SafeAreaView,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
View,
|
|
7
|
+
TextInput,
|
|
8
|
+
ScrollView,
|
|
9
|
+
KeyboardAvoidingView,
|
|
10
|
+
Platform,
|
|
11
|
+
Button,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
|
|
14
|
+
interface ChatProps {
|
|
15
|
+
onSendMessage: (message: string) => Promise<string>;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
theme?: {
|
|
18
|
+
primaryColor?: string;
|
|
19
|
+
backgroundColor?: string;
|
|
20
|
+
textColor?: string;
|
|
21
|
+
};
|
|
3
22
|
}
|
|
4
23
|
|
|
5
|
-
|
|
6
|
-
|
|
24
|
+
const defaultTheme = {
|
|
25
|
+
primaryColor: '#007AFF',
|
|
26
|
+
backgroundColor: '#FFFFFF',
|
|
27
|
+
textColor: '#000000',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Chat: React.FC<ChatProps> = ({
|
|
31
|
+
onSendMessage,
|
|
32
|
+
theme = defaultTheme,
|
|
33
|
+
}) => {
|
|
34
|
+
const [message, setMessage] = React.useState('');
|
|
35
|
+
const [messages, setMessages] = React.useState<Array<{text: string; fromUser: boolean}>>([]);
|
|
36
|
+
|
|
37
|
+
const handleSend = async () => {
|
|
38
|
+
if (!message.trim()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setMessages((prev) => [...prev, { text: message, fromUser: true }]);
|
|
43
|
+
setMessage('');
|
|
44
|
+
|
|
45
|
+
const response = await onSendMessage(message);
|
|
46
|
+
setMessages((prev) => [...prev, { text: response, fromUser: false }]);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const containerStyle = [
|
|
50
|
+
styles.container,
|
|
51
|
+
{
|
|
52
|
+
backgroundColor: theme.backgroundColor,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const getMessageStyle = (fromUser: boolean) => [
|
|
57
|
+
styles.messageBubble,
|
|
58
|
+
fromUser ? styles.userMessage : styles.botMessage,
|
|
59
|
+
{ backgroundColor: fromUser ? theme.primaryColor : '#E8E8E8' },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const getTextStyle = (fromUser: boolean) => [
|
|
63
|
+
styles.messageText,
|
|
64
|
+
{ color: fromUser ? '#fff' : theme.textColor },
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<SafeAreaView style={containerStyle} testID="chat-container">
|
|
69
|
+
<KeyboardAvoidingView
|
|
70
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
71
|
+
style={styles.content}
|
|
72
|
+
>
|
|
73
|
+
<ScrollView style={styles.messagesContainer}>
|
|
74
|
+
{messages.map((msg, i) => (
|
|
75
|
+
<View
|
|
76
|
+
key={i}
|
|
77
|
+
style={getMessageStyle(msg.fromUser)}
|
|
78
|
+
>
|
|
79
|
+
<Text style={getTextStyle(msg.fromUser)}>
|
|
80
|
+
{msg.text}
|
|
81
|
+
</Text>
|
|
82
|
+
</View>
|
|
83
|
+
))}
|
|
84
|
+
</ScrollView>
|
|
85
|
+
<View style={styles.inputContainer}>
|
|
86
|
+
<TextInput
|
|
87
|
+
style={[styles.input, { color: theme.textColor }]}
|
|
88
|
+
value={message}
|
|
89
|
+
onChangeText={setMessage}
|
|
90
|
+
placeholder="Type a message..."
|
|
91
|
+
placeholderTextColor="#999"
|
|
92
|
+
/>
|
|
93
|
+
<Button
|
|
94
|
+
title="Send"
|
|
95
|
+
onPress={handleSend}
|
|
96
|
+
color={theme.primaryColor}
|
|
97
|
+
/>
|
|
98
|
+
</View>
|
|
99
|
+
</KeyboardAvoidingView>
|
|
100
|
+
</SafeAreaView>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
container: {
|
|
106
|
+
flex: 1,
|
|
107
|
+
backgroundColor: '#FFFFFF',
|
|
108
|
+
},
|
|
109
|
+
content: {
|
|
110
|
+
flex: 1,
|
|
111
|
+
backgroundColor: '#F8F9FA',
|
|
112
|
+
},
|
|
113
|
+
messagesContainer: {
|
|
114
|
+
flex: 1,
|
|
115
|
+
padding: 20,
|
|
116
|
+
paddingTop: 30,
|
|
117
|
+
},
|
|
118
|
+
messageBubble: {
|
|
119
|
+
maxWidth: '85%',
|
|
120
|
+
padding: 16,
|
|
121
|
+
borderRadius: 20,
|
|
122
|
+
marginBottom: 16,
|
|
123
|
+
backgroundColor: '#FFFFFF',
|
|
124
|
+
shadowColor: '#000',
|
|
125
|
+
shadowOffset: {
|
|
126
|
+
width: 0,
|
|
127
|
+
height: 2,
|
|
128
|
+
},
|
|
129
|
+
shadowOpacity: 0.05,
|
|
130
|
+
shadowRadius: 8,
|
|
131
|
+
elevation: 3,
|
|
132
|
+
},
|
|
133
|
+
userMessage: {
|
|
134
|
+
alignSelf: 'flex-end',
|
|
135
|
+
backgroundColor: '#FFFFFF',
|
|
136
|
+
borderWidth: 1,
|
|
137
|
+
borderColor: 'rgba(0, 0, 0, 0.04)',
|
|
138
|
+
},
|
|
139
|
+
botMessage: {
|
|
140
|
+
alignSelf: 'flex-start',
|
|
141
|
+
backgroundColor: '#FFFFFF',
|
|
142
|
+
borderWidth: 1,
|
|
143
|
+
borderColor: 'rgba(0, 0, 0, 0.04)',
|
|
144
|
+
},
|
|
145
|
+
messageText: {
|
|
146
|
+
fontSize: 15,
|
|
147
|
+
lineHeight: 22,
|
|
148
|
+
fontWeight: '400',
|
|
149
|
+
color: '#2C2C2E',
|
|
150
|
+
letterSpacing: 0.2,
|
|
151
|
+
},
|
|
152
|
+
inputContainer: {
|
|
153
|
+
flexDirection: 'row',
|
|
154
|
+
alignItems: 'center',
|
|
155
|
+
paddingHorizontal: 16,
|
|
156
|
+
paddingVertical: 12,
|
|
157
|
+
backgroundColor: '#FFFFFF',
|
|
158
|
+
borderTopWidth: 1,
|
|
159
|
+
borderTopColor: 'rgba(0, 0, 0, 0.06)',
|
|
160
|
+
shadowColor: '#000',
|
|
161
|
+
shadowOffset: {
|
|
162
|
+
width: 0,
|
|
163
|
+
height: -8,
|
|
164
|
+
},
|
|
165
|
+
shadowOpacity: 0.04,
|
|
166
|
+
shadowRadius: 12,
|
|
167
|
+
elevation: 8,
|
|
168
|
+
marginTop: 'auto',
|
|
169
|
+
},
|
|
170
|
+
input: {
|
|
171
|
+
flex: 1,
|
|
172
|
+
backgroundColor: '#F8F9FA',
|
|
173
|
+
borderRadius: 16,
|
|
174
|
+
borderWidth: 1,
|
|
175
|
+
borderColor: 'rgba(0, 0, 0, 0.06)',
|
|
176
|
+
paddingHorizontal: 20,
|
|
177
|
+
paddingVertical: 12,
|
|
178
|
+
marginRight: 12,
|
|
179
|
+
fontSize: 15,
|
|
180
|
+
maxHeight: 120,
|
|
181
|
+
color: '#2C2C2E',
|
|
182
|
+
shadowColor: '#000',
|
|
183
|
+
shadowOffset: {
|
|
184
|
+
width: 0,
|
|
185
|
+
height: 1,
|
|
186
|
+
},
|
|
187
|
+
shadowOpacity: 0.04,
|
|
188
|
+
shadowRadius: 4,
|
|
189
|
+
elevation: 2,
|
|
190
|
+
},
|
|
191
|
+
});
|
package/README.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# react-native-srschat
|
|
2
|
-
|
|
3
|
-
srschat
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install react-native-srschat
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```js
|
|
15
|
-
import { multiply } from 'react-native-srschat';
|
|
16
|
-
|
|
17
|
-
// ...
|
|
18
|
-
|
|
19
|
-
const result = await multiply(3, 7);
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Contributing
|
|
24
|
-
|
|
25
|
-
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
26
|
-
|
|
27
|
-
## License
|
|
28
|
-
|
|
29
|
-
MIT
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
#
|
|
3
|
-
# This source code is licensed under the MIT license found in the
|
|
4
|
-
# LICENSE file in the root directory of this source tree.
|
|
5
|
-
|
|
6
|
-
cmake_minimum_required(VERSION 3.13)
|
|
7
|
-
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
8
|
-
|
|
9
|
-
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNSrschatSpec/*.cpp)
|
|
10
|
-
|
|
11
|
-
add_library(
|
|
12
|
-
react_codegen_RNSrschatSpec
|
|
13
|
-
OBJECT
|
|
14
|
-
${react_codegen_SRCS}
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
target_include_directories(react_codegen_RNSrschatSpec PUBLIC . react/renderer/components/RNSrschatSpec)
|
|
18
|
-
|
|
19
|
-
target_link_libraries(
|
|
20
|
-
react_codegen_RNSrschatSpec
|
|
21
|
-
fbjni
|
|
22
|
-
jsi
|
|
23
|
-
# We need to link different libraries based on whether we are building rncore or not, that's necessary
|
|
24
|
-
# because we want to break a circular dependency between react_codegen_rncore and reactnative
|
|
25
|
-
reactnative
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
target_compile_options(
|
|
29
|
-
react_codegen_RNSrschatSpec
|
|
30
|
-
PRIVATE
|
|
31
|
-
-DLOG_TAG=\"ReactNative\"
|
|
32
|
-
-fexceptions
|
|
33
|
-
-frtti
|
|
34
|
-
-std=c++20
|
|
35
|
-
-Wall
|
|
36
|
-
)
|
package/android/generated/android/app/build/generated/source/codegen/jni/RNSrschatSpec-generated.cpp
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
-
*
|
|
5
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
-
* once the code is regenerated.
|
|
7
|
-
*
|
|
8
|
-
* @generated by codegen project: GenerateModuleJniCpp.js
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
#include "RNSrschatSpec.h"
|
|
12
|
-
|
|
13
|
-
namespace facebook::react {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
std::shared_ptr<TurboModule> RNSrschatSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
18
|
-
|
|
19
|
-
return nullptr;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
} // namespace facebook::react
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
-
*
|
|
5
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
-
* once the code is regenerated.
|
|
7
|
-
*
|
|
8
|
-
* @generated by codegen project: GenerateModuleJniH.js
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
#pragma once
|
|
12
|
-
|
|
13
|
-
#include <ReactCommon/JavaTurboModule.h>
|
|
14
|
-
#include <ReactCommon/TurboModule.h>
|
|
15
|
-
#include <jsi/jsi.h>
|
|
16
|
-
|
|
17
|
-
namespace facebook::react {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
JSI_EXPORT
|
|
22
|
-
std::shared_ptr<TurboModule> RNSrschatSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
23
|
-
|
|
24
|
-
} // namespace facebook::react
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GenerateModuleCpp.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
#include "RNSrschatSpecJSI.h"
|
|
11
|
-
|
|
12
|
-
namespace facebook::react {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} // namespace facebook::react
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GenerateModuleH.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
#pragma once
|
|
11
|
-
|
|
12
|
-
#include <ReactCommon/TurboModule.h>
|
|
13
|
-
#include <react/bridging/Bridging.h>
|
|
14
|
-
|
|
15
|
-
namespace facebook::react {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} // namespace facebook::react
|