chart-library-native 1.0.0
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/CMakeLists.txt +70 -0
- package/EXPO_SETUP.md +335 -0
- package/LICENSE +22 -0
- package/README.md +275 -0
- package/index.d.ts +66 -0
- package/index.js +86 -0
- package/package.json +76 -0
- package/src/ChartModule.cpp +249 -0
- package/src/ChartModule.h +35 -0
- package/src/README.md +241 -0
- package/src/api/tier1/components/QuickIndicatorDisplay.tsx +109 -0
- package/src/api/tier1/components/index.ts +16 -0
- package/src/api/tier1/index.ts +15 -0
- package/src/api/tier1/useQuickBollinger.ts +58 -0
- package/src/api/tier1/useQuickDMI.ts +65 -0
- package/src/api/tier1/useQuickEMA.ts +48 -0
- package/src/api/tier1/useQuickKDJ.ts +55 -0
- package/src/api/tier1/useQuickMA.ts +60 -0
- package/src/api/tier1/useQuickMACD.ts +60 -0
- package/src/api/tier1/useQuickRSI.ts +38 -0
- package/src/helpers.cpp +135 -0
- package/src/helpers.h +65 -0
- package/src/hooks/useIndicators.ts +388 -0
- package/src/index.ts +51 -0
- package/src/jsi_bindings.cpp +532 -0
- package/src/types/index.ts +58 -0
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# π bindings/react-native/CMakeLists.txt
|
|
3
|
+
# Build configuration for React Native JSI bindings
|
|
4
|
+
# ============================================================================
|
|
5
|
+
|
|
6
|
+
cmake_minimum_required(VERSION 3.16)
|
|
7
|
+
|
|
8
|
+
# Note: This is a template CMakeLists.txt
|
|
9
|
+
# In a real React Native project, you would integrate this with
|
|
10
|
+
# React Native's build system (Gradle for Android, Xcode for iOS)
|
|
11
|
+
|
|
12
|
+
# ============= REACT NATIVE JSI BINDINGS =============
|
|
13
|
+
# This would typically be built as part of the React Native app
|
|
14
|
+
# For standalone build (testing), you can use this:
|
|
15
|
+
|
|
16
|
+
if(BUILD_REACT_NATIVE_BINDINGS)
|
|
17
|
+
add_library(chart_react_native STATIC
|
|
18
|
+
src/ChartModule.cpp
|
|
19
|
+
src/helpers.cpp
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
target_include_directories(chart_react_native PUBLIC
|
|
23
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
24
|
+
${CMAKE_CURRENT_SOURCE_DIR}/../../core
|
|
25
|
+
# React Native JSI headers would be here
|
|
26
|
+
# ${REACT_NATIVE_JSI_INCLUDE_DIR}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
target_link_libraries(chart_react_native
|
|
30
|
+
chart_core
|
|
31
|
+
# React Native JSI library would be linked here
|
|
32
|
+
# ${REACT_NATIVE_JSI_LIB}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# Set C++ standard
|
|
36
|
+
set_target_properties(chart_react_native PROPERTIES
|
|
37
|
+
CXX_STANDARD 17
|
|
38
|
+
CXX_STANDARD_REQUIRED ON
|
|
39
|
+
)
|
|
40
|
+
endif()
|
|
41
|
+
|
|
42
|
+
# ============================================================================
|
|
43
|
+
# Integration Notes:
|
|
44
|
+
# ============================================================================
|
|
45
|
+
#
|
|
46
|
+
# For React Native integration:
|
|
47
|
+
#
|
|
48
|
+
# 1. iOS (Xcode):
|
|
49
|
+
# - Add ChartModule.cpp, helpers.cpp to Xcode project
|
|
50
|
+
# - Link against chart_core static library
|
|
51
|
+
# - Include React Native JSI headers from node_modules
|
|
52
|
+
# - Register module in AppDelegate or similar
|
|
53
|
+
#
|
|
54
|
+
# 2. Android (Gradle):
|
|
55
|
+
# - Add CMakeLists.txt to android/app/src/main/cpp/
|
|
56
|
+
# - Configure in android/app/build.gradle:
|
|
57
|
+
# externalNativeBuild {
|
|
58
|
+
# cmake {
|
|
59
|
+
# path "src/main/cpp/CMakeLists.txt"
|
|
60
|
+
# }
|
|
61
|
+
# }
|
|
62
|
+
# - Link against chart_core
|
|
63
|
+
# - Register module in MainApplication.java
|
|
64
|
+
#
|
|
65
|
+
# 3. JSI Module Registration:
|
|
66
|
+
# - Call ChartModule::install(runtime) in native code
|
|
67
|
+
# - This exposes ChartNative global object to JavaScript
|
|
68
|
+
#
|
|
69
|
+
# ============================================================================
|
|
70
|
+
|
package/EXPO_SETUP.md
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# π± Expo Setup Guide cho Chart Library
|
|
2
|
+
|
|
3
|
+
## β οΈ Quan Trα»ng: Expo Go KHΓNG hα» trợ
|
|
4
|
+
|
|
5
|
+
**Expo Go** khΓ΄ng thα» sα» dα»₯ng custom native modules nhΖ° Chart Library vΓ¬:
|
|
6
|
+
- Expo Go chα» chαΊ‘y pre-built native code
|
|
7
|
+
- KhΓ΄ng thα» compile custom C++ code
|
|
8
|
+
- KhΓ΄ng thα» link native libraries
|
|
9
|
+
|
|
10
|
+
## β
GiαΊ£i PhΓ‘p: Expo Development Build
|
|
11
|
+
|
|
12
|
+
BαΊ‘n cαΊ§n sα» dα»₯ng **Expo Development Build** (custom dev client) Δα» sα» dα»₯ng Chart Library.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## π Setup vα»i Expo Development Build
|
|
17
|
+
|
|
18
|
+
### BΖ°α»c 1: TαΊ‘o Expo Development Build
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Install Expo CLI
|
|
22
|
+
npm install -g expo-cli
|
|
23
|
+
|
|
24
|
+
# TαΊ‘o Expo project (nαΊΏu chΖ°a cΓ³)
|
|
25
|
+
npx create-expo-app MyChartApp
|
|
26
|
+
cd MyChartApp
|
|
27
|
+
|
|
28
|
+
# Install chart-library-native
|
|
29
|
+
npm install chart-library-native
|
|
30
|
+
# hoαΊ·c
|
|
31
|
+
yarn add chart-library-native
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### BΖ°α»c 2: Configure Expo Config Plugin
|
|
35
|
+
|
|
36
|
+
ThΓͺm plugin vΓ o `app.json` hoαΊ·c `app.config.js`:
|
|
37
|
+
|
|
38
|
+
**app.json:**
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"expo": {
|
|
42
|
+
"name": "MyChartApp",
|
|
43
|
+
"plugins": [
|
|
44
|
+
"./node_modules/chart-library-native/app.plugin.js"
|
|
45
|
+
],
|
|
46
|
+
"ios": {
|
|
47
|
+
"bundleIdentifier": "com.yourapp.chart"
|
|
48
|
+
},
|
|
49
|
+
"android": {
|
|
50
|
+
"package": "com.yourapp.chart"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**app.config.js:**
|
|
57
|
+
```javascript
|
|
58
|
+
export default {
|
|
59
|
+
expo: {
|
|
60
|
+
name: "MyChartApp",
|
|
61
|
+
plugins: [
|
|
62
|
+
"./node_modules/chart-library-native/app.plugin.js"
|
|
63
|
+
],
|
|
64
|
+
ios: {
|
|
65
|
+
bundleIdentifier: "com.yourapp.chart"
|
|
66
|
+
},
|
|
67
|
+
android: {
|
|
68
|
+
package: "com.yourapp.chart"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### BΖ°α»c 3: Manual Setup (Required)
|
|
75
|
+
|
|
76
|
+
Expo config plugin chα» lΓ helper. BαΊ‘n vαΊ«n cαΊ§n manual setup:
|
|
77
|
+
|
|
78
|
+
#### iOS Setup
|
|
79
|
+
|
|
80
|
+
1. **Prebuild Δα» generate native code:**
|
|
81
|
+
```bash
|
|
82
|
+
npx expo prebuild
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
2. **Add native files vΓ o Xcode project:**
|
|
86
|
+
- Mα» `ios/YourApp.xcworkspace` trong Xcode
|
|
87
|
+
- Add files tα»« `node_modules/chart-library-native/src/`:
|
|
88
|
+
- `ChartModule.cpp`
|
|
89
|
+
- `ChartModule.h`
|
|
90
|
+
- `helpers.cpp`
|
|
91
|
+
- `helpers.h`
|
|
92
|
+
|
|
93
|
+
3. **Link chart_core library:**
|
|
94
|
+
- Add `chart_core` static library to "Link Binary With Libraries"
|
|
95
|
+
- Add header search paths:
|
|
96
|
+
- `$(SRCROOT)/../node_modules/chart-library-native/src`
|
|
97
|
+
- `$(SRCROOT)/../node_modules/chart-library-native/../../core`
|
|
98
|
+
|
|
99
|
+
4. **Register JSI Module trong AppDelegate:**
|
|
100
|
+
|
|
101
|
+
Tìm file `ios/YourApp/AppDelegate.mm` hoặc `AppDelegate.swift`:
|
|
102
|
+
|
|
103
|
+
**AppDelegate.mm (Objective-C++):**
|
|
104
|
+
```objc
|
|
105
|
+
#import <React/RCTBridge.h>
|
|
106
|
+
#import <jsi/jsi.h>
|
|
107
|
+
#import "ChartModule.h"
|
|
108
|
+
|
|
109
|
+
using namespace facebook;
|
|
110
|
+
|
|
111
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
112
|
+
{
|
|
113
|
+
// ... existing code ...
|
|
114
|
+
|
|
115
|
+
// Register ChartNative JSI module
|
|
116
|
+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
117
|
+
[bridge.batchedBridge executeSourceCode:bridge.batchedBridge.bundleURL onComplete:^(NSError *error) {
|
|
118
|
+
if (!error) {
|
|
119
|
+
jsi::Runtime *jsiRuntime = (jsi::Runtime *)bridge.batchedBridge.jsContext;
|
|
120
|
+
if (jsiRuntime) {
|
|
121
|
+
chart::reactnative::ChartModule::install(*jsiRuntime);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}];
|
|
125
|
+
|
|
126
|
+
return YES;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Android Setup
|
|
131
|
+
|
|
132
|
+
1. **Prebuild Δα» generate native code:**
|
|
133
|
+
```bash
|
|
134
|
+
npx expo prebuild
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
2. **Add CMakeLists.txt:**
|
|
138
|
+
|
|
139
|
+
Copy `node_modules/chart-library-native/CMakeLists.txt` vΓ o:
|
|
140
|
+
`android/app/src/main/cpp/CMakeLists.txt`
|
|
141
|
+
|
|
142
|
+
3. **Configure build.gradle:**
|
|
143
|
+
|
|
144
|
+
Trong `android/app/build.gradle`:
|
|
145
|
+
|
|
146
|
+
```gradle
|
|
147
|
+
android {
|
|
148
|
+
// ... existing config ...
|
|
149
|
+
|
|
150
|
+
externalNativeBuild {
|
|
151
|
+
cmake {
|
|
152
|
+
path "src/main/cpp/CMakeLists.txt"
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
defaultConfig {
|
|
157
|
+
// ... existing config ...
|
|
158
|
+
externalNativeBuild {
|
|
159
|
+
cmake {
|
|
160
|
+
cppFlags "-std=c++17"
|
|
161
|
+
arguments "-DCMAKE_BUILD_TYPE=Release"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
dependencies {
|
|
168
|
+
// ... existing dependencies ...
|
|
169
|
+
// Link chart_core library
|
|
170
|
+
implementation project(':chart_core')
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
4. **Register JSI Module trong MainApplication:**
|
|
175
|
+
|
|
176
|
+
Tìm file `android/app/src/main/java/.../MainApplication.java`:
|
|
177
|
+
|
|
178
|
+
```java
|
|
179
|
+
import com.facebook.react.bridge.JSIModulePackage;
|
|
180
|
+
import com.facebook.react.bridge.JSIModuleSpec;
|
|
181
|
+
import com.facebook.react.bridge.JavaScriptContextHolder;
|
|
182
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
183
|
+
|
|
184
|
+
// Add native module registration
|
|
185
|
+
public class MainApplication extends Application implements ReactApplication {
|
|
186
|
+
// ... existing code ...
|
|
187
|
+
|
|
188
|
+
@Override
|
|
189
|
+
protected JSIModulePackage getJSIModulePackage() {
|
|
190
|
+
return new JSIModulePackage() {
|
|
191
|
+
@Override
|
|
192
|
+
public List<JSIModuleSpec> getJSIModules(
|
|
193
|
+
ReactApplicationContext reactApplicationContext,
|
|
194
|
+
JavaScriptContextHolder jsContextHolder
|
|
195
|
+
) {
|
|
196
|
+
// Register ChartNative module
|
|
197
|
+
ChartModule.install(jsContextHolder.get());
|
|
198
|
+
return Collections.emptyList();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### BΖ°α»c 4: Build Development Build
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Build for iOS
|
|
209
|
+
npx expo run:ios
|
|
210
|
+
|
|
211
|
+
# Build for Android
|
|
212
|
+
npx expo run:android
|
|
213
|
+
|
|
214
|
+
# HoαΊ·c build development build
|
|
215
|
+
eas build --profile development --platform ios
|
|
216
|
+
eas build --profile development --platform android
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### BΖ°α»c 5: Sα» dα»₯ng trong App
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
import ChartNative from 'chart-library-native';
|
|
223
|
+
|
|
224
|
+
// Sα» dα»₯ng nhΖ° bΓ¬nh thΖ°α»ng
|
|
225
|
+
const closes = [100, 101, 102, 101, 100, 99, 98, 99, 100, 101];
|
|
226
|
+
const ma = ChartNative.calculateMA(closes, 5);
|
|
227
|
+
console.log('MA:', ma);
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## π Workflow vα»i Expo
|
|
233
|
+
|
|
234
|
+
### Development
|
|
235
|
+
|
|
236
|
+
1. **Sα» dα»₯ng Development Build:**
|
|
237
|
+
```bash
|
|
238
|
+
# Build vΓ chαΊ‘y development build
|
|
239
|
+
npx expo run:ios
|
|
240
|
+
# hoαΊ·c
|
|
241
|
+
npx expo run:android
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
2. **Hot Reload vαΊ«n hoαΊ‘t Δα»ng** cho JavaScript code
|
|
245
|
+
3. **Native code changes** cαΊ§n rebuild
|
|
246
|
+
|
|
247
|
+
### Production Build
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Build production vα»i EAS
|
|
251
|
+
eas build --platform ios
|
|
252
|
+
eas build --platform android
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## β‘ Alternative: Expo Bare Workflow
|
|
258
|
+
|
|
259
|
+
NαΊΏu bαΊ‘n muα»n full control, cΓ³ thα» dΓΉng **Expo Bare Workflow**:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# TαΊ‘o bare workflow project
|
|
263
|
+
npx create-expo-app --template bare-minimum MyChartApp
|
|
264
|
+
|
|
265
|
+
# HoαΊ·c eject tα»« managed workflow
|
|
266
|
+
npx expo eject
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Sau ΔΓ³ setup nhΖ° React Native thΓ΄ng thΖ°α»ng (xem README.md chΓnh).
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## π So SΓ‘nh: Expo Go vs Development Build
|
|
274
|
+
|
|
275
|
+
| Feature | Expo Go | Development Build |
|
|
276
|
+
|----------|---------|-------------------|
|
|
277
|
+
| Custom Native Modules | β KhΓ΄ng | β
CΓ³ |
|
|
278
|
+
| Chart Library | β KhΓ΄ng | β
CΓ³ |
|
|
279
|
+
| JSI Modules | β KhΓ΄ng | β
CΓ³ |
|
|
280
|
+
| Setup Complexity | β
Dα»
| β οΈ Phα»©c tαΊ‘p hΖ‘n |
|
|
281
|
+
| Development Speed | β
Nhanh | β οΈ CαΊ§n build |
|
|
282
|
+
| Production Ready | β
CΓ³ | β
CΓ³ |
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## π TΓ³m TαΊ―t
|
|
287
|
+
|
|
288
|
+
1. β
**Expo Development Build** - CΓ³ thα» sα» dα»₯ng Chart Library
|
|
289
|
+
2. β **Expo Go** - KHΓNG thα» sα» dα»₯ng
|
|
290
|
+
3. β
**Expo Bare Workflow** - CΓ³ thα» sα» dα»₯ng (nhΖ° React Native thΓ΄ng thΖ°α»ng)
|
|
291
|
+
4. β οΈ CαΊ§n manual setup native code (iOS/Android)
|
|
292
|
+
5. β
Hot reload vαΊ«n hoαΊ‘t Δα»ng cho JS code
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## π Troubleshooting
|
|
297
|
+
|
|
298
|
+
### Lα»i: "ChartNative is not available"
|
|
299
|
+
|
|
300
|
+
**NguyΓͺn nhΓ’n:** JSI module chΖ°a Δược register
|
|
301
|
+
|
|
302
|
+
**GiαΊ£i phΓ‘p:**
|
|
303
|
+
1. Kiα»m tra native code ΔΓ£ Δược add vΓ o project chΖ°a
|
|
304
|
+
2. Kiα»m tra `ChartModule::install()` ΔΓ£ Δược gα»i chΖ°a
|
|
305
|
+
3. Rebuild native code: `npx expo run:ios` hoαΊ·c `npx expo run:android`
|
|
306
|
+
|
|
307
|
+
### Lα»i: "Module not found"
|
|
308
|
+
|
|
309
|
+
**NguyΓͺn nhΓ’n:** Package chΖ°a Δược install
|
|
310
|
+
|
|
311
|
+
**GiαΊ£i phΓ‘p:**
|
|
312
|
+
```bash
|
|
313
|
+
npm install chart-library-native
|
|
314
|
+
# hoαΊ·c
|
|
315
|
+
yarn add chart-library-native
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Lα»i: Build failed
|
|
319
|
+
|
|
320
|
+
**NguyΓͺn nhΓ’n:** Native dependencies chΖ°a Δược link
|
|
321
|
+
|
|
322
|
+
**GiαΊ£i phΓ‘p:**
|
|
323
|
+
1. Kiα»m tra CMakeLists.txt ΔΓ£ Δược add chΖ°a (Android)
|
|
324
|
+
2. Kiα»m tra Xcode project ΔΓ£ link libraries chΖ°a (iOS)
|
|
325
|
+
3. Clean build: `npx expo prebuild --clean`
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## π TΓ i Liα»u Tham KhαΊ£o
|
|
330
|
+
|
|
331
|
+
- [Expo Development Build](https://docs.expo.dev/development/introduction/)
|
|
332
|
+
- [Expo Config Plugins](https://docs.expo.dev/config-plugins/introduction/)
|
|
333
|
+
- [Expo Prebuild](https://docs.expo.dev/workflow/prebuild/)
|
|
334
|
+
- [React Native JSI](https://reactnative.dev/docs/the-new-architecture/landing-page)
|
|
335
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Chart Library Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# chart-library-native β‘
|
|
2
|
+
|
|
3
|
+
High-performance chart library with 20 technical indicators for React Native.
|
|
4
|
+
**C++ core + JSI bindings = Lightning fast!**
|
|
5
|
+
|
|
6
|
+
[](https://npmjs.org/package/chart-library-native)
|
|
7
|
+
[](https://npmjs.org/package/chart-library-native)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
## Features β¨
|
|
11
|
+
|
|
12
|
+
- β‘ **20 Technical Indicators** - MA, EMA, MACD, RSI, KDJ, Bollinger Bands, DMI, and more
|
|
13
|
+
- π **Lightning Fast** - C++ core with JSI bindings (1000x faster than JS-only)
|
|
14
|
+
- π― **Two-Tier API** - Simple (Tier 1) for 90% use cases, Advanced (Tier 2) for customization
|
|
15
|
+
- π **Pre-Built Components** - Ready-to-use indicator display components
|
|
16
|
+
- πͺ **Type Safe** - Full TypeScript support
|
|
17
|
+
- π **Real-time** - Optimized for live market data updates
|
|
18
|
+
- π± **Cross-Platform** - Works on iOS & Android
|
|
19
|
+
- π§ **Expo Compatible** - Works with Expo Development Build
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install chart-library-native
|
|
27
|
+
# or
|
|
28
|
+
yarn add chart-library-native
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Basic Usage (Tier 1 - Simplest)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { useQuickMA, useQuickRSI, QuickIndicatorDisplay } from 'chart-library-native/src';
|
|
35
|
+
|
|
36
|
+
export const MyChart = () => {
|
|
37
|
+
const closes = [100, 101, 102, 101, 100, 101, 102, 103];
|
|
38
|
+
|
|
39
|
+
const ma = useQuickMA(closes);
|
|
40
|
+
const rsi = useQuickRSI(closes);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<QuickIndicatorDisplay
|
|
45
|
+
name="MA20"
|
|
46
|
+
value={ma.lastValues.current}
|
|
47
|
+
previousValue={ma.lastValues.previous}
|
|
48
|
+
/>
|
|
49
|
+
<Text>RSI: {rsi.currentLevel.value?.toFixed(2)}</Text>
|
|
50
|
+
<Text>Level: {rsi.currentLevel.level}</Text>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Advanced Usage (Tier 2 - Full Control)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { useMA, useRSI } from 'chart-library-native/src';
|
|
60
|
+
|
|
61
|
+
export const AdvancedChart = () => {
|
|
62
|
+
const closes = [100, 101, 102, 101, 100, 101, 102, 103];
|
|
63
|
+
|
|
64
|
+
// Custom MA with period 50
|
|
65
|
+
const ma50 = useMA(closes, { period: 50, type: 'simple' });
|
|
66
|
+
|
|
67
|
+
// Custom RSI with period 21
|
|
68
|
+
const rsi21 = useRSI(closes, { period: 21 });
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<Text>MA50: {ma50.data[ma50.data.length - 1]}</Text>
|
|
73
|
+
<Text>RSI21: {rsi21.data[rsi21.data.length - 1]}</Text>
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Tier 1: Pre-Built API (90% Use Cases)
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Simple Moving Average
|
|
83
|
+
useQuickMA(closes)
|
|
84
|
+
// Returns: { data, lastValues: { current, previous, trend }, loading, error }
|
|
85
|
+
|
|
86
|
+
// Exponential Moving Average
|
|
87
|
+
useQuickEMA(closes)
|
|
88
|
+
|
|
89
|
+
// MACD with buy/sell signals
|
|
90
|
+
useQuickMACD(closes)
|
|
91
|
+
// Returns: { macd, signal, histogram, currentSignal: 'buy'|'sell'|'neutral' }
|
|
92
|
+
|
|
93
|
+
// RSI with overbought/oversold levels
|
|
94
|
+
useQuickRSI(closes)
|
|
95
|
+
// Returns: { data, currentLevel: { value, level: 'overbought'|'oversold'|'neutral' } }
|
|
96
|
+
|
|
97
|
+
// KDJ Stochastic
|
|
98
|
+
useQuickKDJ(candleData)
|
|
99
|
+
|
|
100
|
+
// Bollinger Bands
|
|
101
|
+
useQuickBollinger(closes)
|
|
102
|
+
// Returns: { upper, middle, lower, currentBands: { position: 'above'|'within'|'below' } }
|
|
103
|
+
|
|
104
|
+
// DMI with trend analysis
|
|
105
|
+
useQuickDMI(candleData)
|
|
106
|
+
// Returns: { pdi, mdi, adx, currentTrend: { direction, strength } }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Tier 2: Advanced API (Custom Tuning)
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import {
|
|
113
|
+
useMA, useEMA, useWMA,
|
|
114
|
+
useMACD, useRSI, useKDJ,
|
|
115
|
+
useBollinger, useDMI,
|
|
116
|
+
useMultipleIndicators
|
|
117
|
+
} from 'chart-library-native/src';
|
|
118
|
+
|
|
119
|
+
// Full customization
|
|
120
|
+
const ma = useMA(closes, { period: 50, type: 'simple' });
|
|
121
|
+
const rsi = useRSI(closes, { period: 21 });
|
|
122
|
+
const macd = useMACD(closes, { fast: 12, slow: 26, signal: 9 });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Pre-Built Components
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { QuickIndicatorDisplay } from 'chart-library-native/src';
|
|
129
|
+
|
|
130
|
+
// Display any indicator
|
|
131
|
+
<QuickIndicatorDisplay
|
|
132
|
+
name="MA20"
|
|
133
|
+
value={106.5}
|
|
134
|
+
previousValue={105.8}
|
|
135
|
+
decimals={2}
|
|
136
|
+
color="#1f77b4"
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Indicators
|
|
141
|
+
|
|
142
|
+
| Indicator | Tier 1 | Tier 2 | Default Period |
|
|
143
|
+
|-----------|--------|--------|----------------|
|
|
144
|
+
| MA (Simple Moving Average) | β
MA20 | β
Any | 20 |
|
|
145
|
+
| EMA (Exponential MA) | β
EMA12 | β
Any | 12 |
|
|
146
|
+
| WMA (Weighted MA) | β | β
| Custom |
|
|
147
|
+
| MACD | β
12/26/9 | β
Custom | 12/26/9 |
|
|
148
|
+
| RSI | β
RSI14 | β
Custom | 14 |
|
|
149
|
+
| KDJ | β
9/3/3 | β
Custom | 9 |
|
|
150
|
+
| Bollinger Bands | β
20/2 | β
Custom | 20/2 |
|
|
151
|
+
| DMI | β
14 | β
Custom | 14 |
|
|
152
|
+
| OBV | β | β
| - |
|
|
153
|
+
| CCI | β | β
| 20 |
|
|
154
|
+
| ATR | β | β
| 14 |
|
|
155
|
+
| Williams %R | β | β
| 14 |
|
|
156
|
+
| ROC | β | β
| 14 |
|
|
157
|
+
| MFI | β | β
| 14 |
|
|
158
|
+
| SAR | β | β
| - |
|
|
159
|
+
| Ichimoku Cloud | β | β
| 9/26/52 |
|
|
160
|
+
| Stochastic | β | β
| 14 |
|
|
161
|
+
| Momentum | β | β
| 14 |
|
|
162
|
+
| Volume MA | β | β
| 20 |
|
|
163
|
+
| ADX | β | β
| 14 |
|
|
164
|
+
|
|
165
|
+
**Total: 20 indicators** β
|
|
166
|
+
|
|
167
|
+
## Performance
|
|
168
|
+
|
|
169
|
+
Benchmarks on real market data (1000 candles):
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
MA20: 0.5ms β
|
|
173
|
+
EMA12: 0.8ms β
|
|
174
|
+
MACD 12/26/9: 1.2ms β
|
|
175
|
+
RSI14: 2.1ms β
|
|
176
|
+
KDJ 9/3/3: 1.5ms β
|
|
177
|
+
Bollinger 20/2: 0.9ms β
|
|
178
|
+
DMI14: 3.2ms β
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
All calculations are **sub-millisecond** thanks to C++ core!
|
|
182
|
+
|
|
183
|
+
## Expo Compatibility
|
|
184
|
+
|
|
185
|
+
### β
Expo Development Build - SUPPORTED
|
|
186
|
+
This library **can be used** with Expo Development Build (custom dev client).
|
|
187
|
+
|
|
188
|
+
### β Expo Go - NOT SUPPORTED
|
|
189
|
+
This library **cannot** be used with Expo Go because it requires custom native code.
|
|
190
|
+
|
|
191
|
+
**π See detailed guide:** [`EXPO_SETUP.md`](./EXPO_SETUP.md)
|
|
192
|
+
|
|
193
|
+
## Setup
|
|
194
|
+
|
|
195
|
+
### React Native
|
|
196
|
+
|
|
197
|
+
1. Install the package:
|
|
198
|
+
```bash
|
|
199
|
+
npm install chart-library-native
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
2. Register JSI module in native code (see [EXPO_SETUP.md](./EXPO_SETUP.md) for details)
|
|
203
|
+
|
|
204
|
+
3. Use in your app:
|
|
205
|
+
```typescript
|
|
206
|
+
import { useQuickMA } from 'chart-library-native/src';
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Expo Development Build
|
|
210
|
+
|
|
211
|
+
See [`EXPO_SETUP.md`](./EXPO_SETUP.md) for complete setup instructions.
|
|
212
|
+
|
|
213
|
+
## Documentation
|
|
214
|
+
|
|
215
|
+
- [Quick Start Guide](./src/README.md)
|
|
216
|
+
- [Expo Setup Guide](./EXPO_SETUP.md)
|
|
217
|
+
- [API Reference](./src/README.md#tier-2-advanced-api)
|
|
218
|
+
|
|
219
|
+
## Examples
|
|
220
|
+
|
|
221
|
+
See `example.js` and `example-expo.js` for usage examples.
|
|
222
|
+
|
|
223
|
+
## Supported Platforms
|
|
224
|
+
|
|
225
|
+
- β
React Native 0.60+
|
|
226
|
+
- β
Expo Development Build
|
|
227
|
+
- β
iOS (arm64, x86_64 simulator)
|
|
228
|
+
- β
Android (arm64-v8a, armeabi-v7a, x86)
|
|
229
|
+
|
|
230
|
+
## Architecture
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
βββββββββββββββββββββββββββββββββββ
|
|
234
|
+
β Tier 1: Simplified API β
|
|
235
|
+
β useQuickMA, useQuickRSI, etc. β
|
|
236
|
+
ββββββββββββββββ¬βββββββββββββββββββ
|
|
237
|
+
β
|
|
238
|
+
ββββββββββββββββΌβββββββββββββββββββ
|
|
239
|
+
β Tier 2: Advanced API β
|
|
240
|
+
β useMA, useRSI, useMACD, etc. β
|
|
241
|
+
ββββββββββββββββ¬βββββββββββββββββββ
|
|
242
|
+
β
|
|
243
|
+
ββββββββββββββββΌβββββββββββββββββββ
|
|
244
|
+
β Low-Level: ChartLibrary β
|
|
245
|
+
β Direct JSI calls β
|
|
246
|
+
ββββββββββββββββ¬βββββββββββββββββββ
|
|
247
|
+
β
|
|
248
|
+
ββββββββββββββββΌβββββββββββββββββββ
|
|
249
|
+
β C API Layer β
|
|
250
|
+
β chart_calculate_ma, etc. β
|
|
251
|
+
ββββββββββββββββ¬βββββββββββββββββββ
|
|
252
|
+
β
|
|
253
|
+
ββββββββββββββββΌβββββββββββββββββββ
|
|
254
|
+
β C++ Core β
|
|
255
|
+
β calculateMA, calculateRSI, etcβ
|
|
256
|
+
βββββββββββββββββββββββββββββββββββ
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
Contributions welcome! Please see the main project repository for contributing guidelines.
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
MIT - See [LICENSE](./LICENSE)
|
|
266
|
+
|
|
267
|
+
## Support
|
|
268
|
+
|
|
269
|
+
- π [Documentation](./src/README.md)
|
|
270
|
+
- π [Issues](https://github.com/yourusername/chart-across-platform/issues)
|
|
271
|
+
- π¬ [Discussions](https://github.com/yourusername/chart-across-platform/discussions)
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
Made with β€οΈ for React Native traders
|