react-native-vroom-chart 0.4.0 → 0.6.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/android/CMakeLists.txt +143 -0
- package/android/README.md +60 -5
- package/android/build.gradle +115 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/VroomChartJni.cpp +24 -0
- package/android/src/main/java/com/vroom/chart/VroomChartModule.kt +31 -0
- package/android/src/main/java/com/vroom/chart/VroomChartPackage.kt +31 -0
- package/cpp/VroomChartHostObject.cpp +265 -1
- package/cpp/VroomJsiInstaller.cpp +11 -1
- package/cpp/VroomSkiaContext.cpp +15 -7
- package/cpp/_core_include/vroom/vroom_chart.h +95 -0
- package/cpp/_core_src/bollinger.cpp +43 -0
- package/cpp/_core_src/bollinger.h +31 -0
- package/cpp/_core_src/chart.cpp +56 -0
- package/cpp/_core_src/chart.h +45 -0
- package/cpp/_core_src/chart_facade.cpp +117 -0
- package/cpp/_core_src/ma_overlay.cpp +67 -0
- package/cpp/_core_src/ma_overlay.h +21 -0
- package/cpp/_core_src/price_line_layout.cpp +87 -0
- package/cpp/_core_src/price_line_layout.h +80 -0
- package/cpp/_core_src/price_lines.cpp +428 -0
- package/cpp/_core_src/price_lines.h +56 -0
- package/lib/index.d.mts +201 -1
- package/lib/index.d.ts +201 -1
- package/lib/index.js +122 -7
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +122 -7
- package/lib/index.mjs.map +1 -1
- package/package.json +20 -8
- package/react-native-vroom-chart.podspec +1 -1
- package/src/VroomChart.tsx +95 -8
- package/src/index.ts +3 -0
- package/src/jsi.d.ts +68 -0
- package/src/types.ts +3 -0
- package/src/useChartCore.ts +98 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# android/CMakeLists.txt
|
|
2
|
+
#
|
|
3
|
+
# Builds libvroomchart.so from the same platform-agnostic JSI glue and chart
|
|
4
|
+
# core the iOS podspec compiles (see ../react-native-vroom-chart.podspec),
|
|
5
|
+
# plus this directory's small JNI entry point (src/main/cpp/VroomChartJni.cpp).
|
|
6
|
+
#
|
|
7
|
+
# RN-Skia's headers (JsiSkHostObjects.h, RNSkPlatformContext.h — needed by
|
|
8
|
+
# ../cpp/VroomSkiaContext.cpp) aren't consumed via CMake's prefab mechanism;
|
|
9
|
+
# instead we point directly at @shopify/react-native-skia's `cpp/` sources,
|
|
10
|
+
# mirroring the podspec's `require.resolve('@shopify/react-native-skia/package.json')`
|
|
11
|
+
# trick (VROOM_SKIA_CPP_DIR is computed the same way in build.gradle).
|
|
12
|
+
#
|
|
13
|
+
# IMPORTANT — SK_GRAPHITE ABI note: RNSkPlatformContext's vtable layout
|
|
14
|
+
# differs depending on whether SK_GRAPHITE was defined when RN-Skia's own
|
|
15
|
+
# Android build compiled RNSkAndroidPlatformContext (the concrete class whose
|
|
16
|
+
# vtable we call into via VroomSkiaContext.cpp's `ctx->createFontMgr()`).
|
|
17
|
+
# We must define SK_GRAPHITE identically to however RN-Skia's own CMakeLists
|
|
18
|
+
# (android/CMakeLists.txt) decided it, or virtual calls resolve to the wrong
|
|
19
|
+
# vtable slot. We replicate their libskia.a symbol probe below rather than
|
|
20
|
+
# hard-coding an assumption.
|
|
21
|
+
cmake_minimum_required(VERSION 3.22)
|
|
22
|
+
project(vroomchart)
|
|
23
|
+
|
|
24
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
25
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
26
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
27
|
+
|
|
28
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
29
|
+
# Prefab package name matches the Gradle project name AGP autolinking assigns
|
|
30
|
+
# RN-Skia (":shopify_react-native-skia"), not the "rnskia" module name inside
|
|
31
|
+
# its own `prefab { rnskia { ... } }` block — that block key becomes the
|
|
32
|
+
# `shopify_react-native-skia::rnskia` *target* name below, not the package.
|
|
33
|
+
find_package(shopify_react-native-skia REQUIRED CONFIG)
|
|
34
|
+
|
|
35
|
+
if(NOT DEFINED VROOM_SKIA_CPP_DIR)
|
|
36
|
+
message(FATAL_ERROR "VROOM_SKIA_CPP_DIR not set — passed from android/build.gradle.")
|
|
37
|
+
endif()
|
|
38
|
+
|
|
39
|
+
# RN-Skia's own package root is one level up from its cpp/ dir; its prebuilt
|
|
40
|
+
# Skia static libs live at <root>/libs/android/<abi>/libskia.a.
|
|
41
|
+
get_filename_component(VROOM_SKIA_PKG_DIR "${VROOM_SKIA_CPP_DIR}" DIRECTORY)
|
|
42
|
+
set(VROOM_SKIA_LIBS_DIR "${VROOM_SKIA_PKG_DIR}/libs/android/${ANDROID_ABI}")
|
|
43
|
+
|
|
44
|
+
# Our chart core calls Skia types (SkCanvas, SkPaint, SkFont, ...) and
|
|
45
|
+
# RN-Skia's own JSI plumbing (RNJsi::JsiHostObject, JsiSkPicture, ...)
|
|
46
|
+
# directly — none of that is header-only, and we need *both* libraries:
|
|
47
|
+
# - librnskia.so (RN-Skia's prefab-published `rnskia` module, consumed above
|
|
48
|
+
# via `implementation project(":shopify_react-native-skia")`) for RNJsi's
|
|
49
|
+
# own symbols (JsiHostObject, JsiSkPicture, ...), which only exist there.
|
|
50
|
+
# - libskia.a (RN-Skia's bundled prebuilt Skia static lib) for direct Skia
|
|
51
|
+
# calls (SkCanvas::drawRect, SkFont, ...): librnskia.so links libskia.a
|
|
52
|
+
# internally but doesn't re-export its symbols, so linking librnskia.so
|
|
53
|
+
# alone leaves every direct Skia call undefined.
|
|
54
|
+
# Recompiling RN-Skia's cpp/jsi/*.cpp ourselves instead of linking librnskia.so
|
|
55
|
+
# was considered and rejected — it would duplicate RNJsi's symbols (and their
|
|
56
|
+
# static/global state) across two separately-loaded .so's, which is fine on
|
|
57
|
+
# iOS's single static binary but not here.
|
|
58
|
+
add_library(vroom_skia_prebuilt STATIC IMPORTED)
|
|
59
|
+
set_property(TARGET vroom_skia_prebuilt PROPERTY
|
|
60
|
+
IMPORTED_LOCATION "${VROOM_SKIA_LIBS_DIR}/libskia.a")
|
|
61
|
+
|
|
62
|
+
set(SK_GRAPHITE_AVAILABLE OFF)
|
|
63
|
+
if(EXISTS "${VROOM_SKIA_LIBS_DIR}/libskia.a")
|
|
64
|
+
execute_process(
|
|
65
|
+
COMMAND nm "${VROOM_SKIA_LIBS_DIR}/libskia.a"
|
|
66
|
+
COMMAND grep "dawn::\\|wgpu\\|_ZN4dawn\\|DawnDevice\\|dawn_native"
|
|
67
|
+
OUTPUT_VARIABLE VROOM_NM_OUTPUT
|
|
68
|
+
ERROR_QUIET
|
|
69
|
+
RESULT_VARIABLE VROOM_NM_RESULT
|
|
70
|
+
)
|
|
71
|
+
if(VROOM_NM_RESULT EQUAL 0 AND NOT "${VROOM_NM_OUTPUT}" STREQUAL "")
|
|
72
|
+
set(SK_GRAPHITE_AVAILABLE ON)
|
|
73
|
+
endif()
|
|
74
|
+
endif()
|
|
75
|
+
|
|
76
|
+
# The chart core (shared across iOS/Android/WASM — see ../../core/CMakeLists.txt).
|
|
77
|
+
set(VROOM_CORE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/_core_include")
|
|
78
|
+
set(VROOM_CORE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/_core_src")
|
|
79
|
+
file(GLOB VROOM_CORE_SOURCES CONFIGURE_DEPENDS "${VROOM_CORE_SRC_DIR}/*.cpp")
|
|
80
|
+
|
|
81
|
+
add_library(vroomchart SHARED
|
|
82
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/../cpp/VroomJsiInstaller.cpp"
|
|
83
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/../cpp/VroomChartHostObject.cpp"
|
|
84
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/../cpp/VroomSkiaContext.cpp"
|
|
85
|
+
${VROOM_CORE_SOURCES}
|
|
86
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/VroomChartJni.cpp"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
target_include_directories(vroomchart PRIVATE
|
|
90
|
+
"${VROOM_CORE_INCLUDE_DIR}"
|
|
91
|
+
"${VROOM_CORE_SRC_DIR}"
|
|
92
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/../cpp"
|
|
93
|
+
# RN-Skia headers — mirrors its own android/CMakeLists.txt include list.
|
|
94
|
+
"${VROOM_SKIA_CPP_DIR}"
|
|
95
|
+
"${VROOM_SKIA_CPP_DIR}/api"
|
|
96
|
+
"${VROOM_SKIA_CPP_DIR}/jsi"
|
|
97
|
+
"${VROOM_SKIA_CPP_DIR}/rnskia"
|
|
98
|
+
"${VROOM_SKIA_CPP_DIR}/rnskia/values"
|
|
99
|
+
"${VROOM_SKIA_CPP_DIR}/utils"
|
|
100
|
+
"${VROOM_SKIA_CPP_DIR}/skia"
|
|
101
|
+
"${VROOM_SKIA_CPP_DIR}/dawn/include"
|
|
102
|
+
# RNSkPlatformContext.h pulls in ReactCommon/CallInvoker.h directly, which
|
|
103
|
+
# isn't part of the prefab-published jsi headers — same dirs RN-Skia's own
|
|
104
|
+
# android/CMakeLists.txt adds for the same reason.
|
|
105
|
+
"${REACT_NATIVE_DIR}/ReactCommon"
|
|
106
|
+
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
|
|
107
|
+
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
target_compile_definitions(vroomchart PRIVATE
|
|
111
|
+
SK_BUILD_FOR_ANDROID
|
|
112
|
+
SK_DISABLE_LEGACY_SHAPER_FACTORY
|
|
113
|
+
SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API
|
|
114
|
+
ONANDROID
|
|
115
|
+
ON_ANDROID
|
|
116
|
+
)
|
|
117
|
+
if(SK_GRAPHITE_AVAILABLE)
|
|
118
|
+
target_compile_definitions(vroomchart PRIVATE SK_GRAPHITE)
|
|
119
|
+
else()
|
|
120
|
+
target_compile_definitions(vroomchart PRIVATE SK_GL SK_GANESH)
|
|
121
|
+
endif()
|
|
122
|
+
|
|
123
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 80)
|
|
124
|
+
include("${REACT_NATIVE_DIR}/ReactCommon/cmake-utils/react-native-flags.cmake")
|
|
125
|
+
target_compile_reactnative_options(vroomchart PRIVATE)
|
|
126
|
+
else()
|
|
127
|
+
target_compile_options(vroomchart PRIVATE -fexceptions -frtti -std=c++20 -Wall)
|
|
128
|
+
endif()
|
|
129
|
+
|
|
130
|
+
# ../cpp/_core_include/vroom/vroom_chart.h forward-declares `struct SkCanvas;`
|
|
131
|
+
# (to keep the public C facade header Skia-free); Skia itself declares
|
|
132
|
+
# `class SkCanvas`. This tag mismatch is harmless but react-native-flags.cmake
|
|
133
|
+
# enables -Werror, which would otherwise turn it into a build failure.
|
|
134
|
+
target_compile_options(vroomchart PRIVATE -Wno-mismatched-tags)
|
|
135
|
+
|
|
136
|
+
find_library(VROOM_LOG_LIB log)
|
|
137
|
+
|
|
138
|
+
target_link_libraries(vroomchart
|
|
139
|
+
${VROOM_LOG_LIB}
|
|
140
|
+
ReactAndroid::jsi
|
|
141
|
+
shopify_react-native-skia::rnskia
|
|
142
|
+
vroom_skia_prebuilt
|
|
143
|
+
)
|
package/android/README.md
CHANGED
|
@@ -1,7 +1,62 @@
|
|
|
1
|
-
# Android
|
|
1
|
+
# Android bridge
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Android equivalent of `../ios/`: a small TurboModule
|
|
4
|
+
([`VroomChartModule.kt`](src/main/java/com/vroom/chart/VroomChartModule.kt)) whose
|
|
5
|
+
`install()` hands the JSI runtime pointer to a native `vroomchart` library
|
|
6
|
+
(built by [`CMakeLists.txt`](CMakeLists.txt)) that installs
|
|
7
|
+
`global.VroomChartJSI` via the same platform-agnostic
|
|
8
|
+
[`../cpp/VroomJsiInstaller.cpp`](../cpp/VroomJsiInstaller.cpp) the iOS bridge
|
|
9
|
+
uses.
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
The chart core itself (`../cpp/_core_src`) and the RN-Skia font/context glue
|
|
12
|
+
(`../cpp/VroomSkiaContext.*`) are unmodified and shared across iOS and
|
|
13
|
+
Android — only the platform glue (this directory + `../ios/`) differs.
|
|
14
|
+
`../cpp/VroomChartHostObject.cpp` has one small `#if defined(__ANDROID__)`
|
|
15
|
+
branch (see "Cross-`.so` Skia objects" below).
|
|
16
|
+
|
|
17
|
+
`build.gradle` resolves `@shopify/react-native-skia`'s `cpp/` sources via
|
|
18
|
+
Node module resolution (mirroring `../react-native-vroom-chart.podspec`'s
|
|
19
|
+
`require.resolve` trick) so `VroomSkiaContext.cpp` can include RN-Skia's
|
|
20
|
+
`JsiSkHostObjects.h` / `RNSkPlatformContext.h`. `CMakeLists.txt` also
|
|
21
|
+
replicates RN-Skia's own Graphite-vs-Ganesh detection (probing its bundled
|
|
22
|
+
`libskia.a`) so `SK_GRAPHITE` is defined identically to however RN-Skia's own
|
|
23
|
+
Android build was compiled — `RNSkPlatformContext`'s vtable layout depends on
|
|
24
|
+
that macro, and a mismatch would corrupt the virtual call in
|
|
25
|
+
`VroomJsiInstaller.cpp`'s `ensureAxisTypeface`.
|
|
26
|
+
|
|
27
|
+
We link two RN-Skia-adjacent libraries into `libvroomchart.so`, for two
|
|
28
|
+
different reasons:
|
|
29
|
+
- `shopify_react-native-skia::rnskia` (RN-Skia's own prefab-published
|
|
30
|
+
shared library, `librnskia.so`) — for `RNJsi::JsiHostObject` and friends,
|
|
31
|
+
whose out-of-line methods are compiled only there.
|
|
32
|
+
- RN-Skia's bundled `libskia.a` (imported directly by path, since it isn't
|
|
33
|
+
prefab-published) — for direct Skia calls (`SkCanvas::drawRect`, `SkFont`,
|
|
34
|
+
...), since `librnskia.so` links `libskia.a` internally but doesn't
|
|
35
|
+
re-export its symbols.
|
|
36
|
+
|
|
37
|
+
### Cross-`.so` Skia objects
|
|
38
|
+
|
|
39
|
+
Unlike iOS (one static binary), Android compiles RN-Skia into its own
|
|
40
|
+
`librnskia.so`, separate from `libvroomchart.so`. That's transparent for most
|
|
41
|
+
of the JSI bridge, but **`RNSkia::JsiSkPicture` — the object `render()` /
|
|
42
|
+
`pan()` / etc. return to JS — can't be constructed directly in
|
|
43
|
+
`libvroomchart.so` on Android.** RN-Skia's own C++ (e.g.
|
|
44
|
+
`cpp/api/recorder/Convertor.h`'s `getPropertyValue<sk_sp<SkPicture>>`, which
|
|
45
|
+
runs whenever `<Picture>` reads the value) does
|
|
46
|
+
`value.asObject(rt).asHostObject<JsiSkPicture>(rt)`, a `dynamic_pointer_cast`
|
|
47
|
+
under the hood. A `JsiSkPicture` we construct ourselves has a vtable/typeinfo
|
|
48
|
+
compiled into *our* `.so`; that cast — running inside `librnskia.so` — sees a
|
|
49
|
+
different, unmerged RTTI record for "the same" class and fails with `Object
|
|
50
|
+
is not a HostObject of desired type`.
|
|
51
|
+
|
|
52
|
+
`VroomChartHostObject.cpp`'s `wrapPicture()` works around this only on
|
|
53
|
+
Android: instead of constructing `RNSkia::JsiSkPicture` directly (as iOS
|
|
54
|
+
does), it serializes the `SkPicture` (`SkPicture::serialize()`) and calls
|
|
55
|
+
RN-Skia's own public JS API, `Skia.Picture.MakePicture(bytes)`, via JSI. That
|
|
56
|
+
runs `JsiSkPictureFactory::MakePicture` — genuinely compiled inside
|
|
57
|
+
`librnskia.so` — so the returned object's RTTI matches what
|
|
58
|
+
`librnskia.so`'s own code expects. This costs a serialize + re-parse of the
|
|
59
|
+
picture's draw commands on every `render()`/gesture call, which is real
|
|
60
|
+
overhead on what's meant to be a 60fps hot path; if that shows up in
|
|
61
|
+
profiling, revisit (e.g. a merged-`.so` build, or a lighter-weight bridge
|
|
62
|
+
that avoids the round trip).
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// android/build.gradle
|
|
2
|
+
//
|
|
3
|
+
// Builds the Android half of the JSI bridge: a small `vroomchart` native
|
|
4
|
+
// library (see CMakeLists.txt) plus the TurboModule that installs it
|
|
5
|
+
// (see src/main/java/com/vroom/chart). Modeled on
|
|
6
|
+
// @shopify/react-native-skia/android/build.gradle and
|
|
7
|
+
// react-native-worklets/android/build.gradle, which solve the same
|
|
8
|
+
// "compile custom C++ against the RN/RN-Skia JSI internals" problem.
|
|
9
|
+
|
|
10
|
+
def safeExtGet(prop, fallback) {
|
|
11
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def reactNativeArchitectures() {
|
|
15
|
+
def value = project.getProperties().get("reactNativeArchitectures")
|
|
16
|
+
return value ? value.split(",") : ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Resolves a package's directory via Node's own module resolution, so this
|
|
20
|
+
// works whether react-native-vroom-chart is installed flat or (as in this
|
|
21
|
+
// monorepo) via pnpm's nested .pnpm store.
|
|
22
|
+
def resolvePackageDir(packageJsonSpecifier) {
|
|
23
|
+
def packageJsonPath = providers.exec {
|
|
24
|
+
workingDir(rootDir)
|
|
25
|
+
commandLine("node", "--print", "require.resolve('${packageJsonSpecifier}')")
|
|
26
|
+
}.standardOutput.asText.get().trim()
|
|
27
|
+
return file(packageJsonPath).parentFile
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def reactNativeDir = resolvePackageDir("react-native/package.json")
|
|
31
|
+
def skiaCppDir = new File(resolvePackageDir("@shopify/react-native-skia/package.json"), "cpp")
|
|
32
|
+
|
|
33
|
+
// Mirror ../cpp/_core_{src,include} from ../../core/{src,include} whenever
|
|
34
|
+
// the monorepo core is present, so edits to packages/core/ propagate on the
|
|
35
|
+
// next build without a separate vendoring step. This matches
|
|
36
|
+
// ../react-native-vroom-chart.podspec's iOS behavior; a published package
|
|
37
|
+
// (no ../../core) falls back to the committed vendored copies instead
|
|
38
|
+
// (see ../scripts/vendor-core.mjs).
|
|
39
|
+
def coreRoot = file("${projectDir}/../../core")
|
|
40
|
+
if (coreRoot.isDirectory()) {
|
|
41
|
+
["src", "include"].each { sub ->
|
|
42
|
+
def dst = file("${projectDir}/../cpp/_core_${sub}")
|
|
43
|
+
delete dst
|
|
44
|
+
copy {
|
|
45
|
+
from "${coreRoot}/${sub}"
|
|
46
|
+
into dst
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
apply plugin: "com.android.library"
|
|
52
|
+
apply plugin: "kotlin-android"
|
|
53
|
+
apply plugin: "com.facebook.react"
|
|
54
|
+
|
|
55
|
+
android {
|
|
56
|
+
namespace "com.vroom.chart"
|
|
57
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 36)
|
|
58
|
+
|
|
59
|
+
if (rootProject.hasProperty("ndkPath")) {
|
|
60
|
+
ndkPath rootProject.ext.ndkPath
|
|
61
|
+
}
|
|
62
|
+
if (rootProject.hasProperty("ndkVersion")) {
|
|
63
|
+
ndkVersion rootProject.ext.ndkVersion
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
68
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 36)
|
|
69
|
+
|
|
70
|
+
externalNativeBuild {
|
|
71
|
+
cmake {
|
|
72
|
+
abiFilters(*reactNativeArchitectures())
|
|
73
|
+
arguments "-DANDROID_STL=c++_shared",
|
|
74
|
+
"-DREACT_NATIVE_DIR=${reactNativeDir}",
|
|
75
|
+
"-DVROOM_SKIA_CPP_DIR=${skiaCppDir}"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
buildFeatures {
|
|
81
|
+
// Consumes the `ReactAndroid` prefab package (published by
|
|
82
|
+
// com.facebook.react:react-android) so CMake can `find_package(ReactAndroid)`
|
|
83
|
+
// for the jsi headers/library without us hand-resolving RN's AAR layout.
|
|
84
|
+
prefab true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
externalNativeBuild {
|
|
88
|
+
cmake {
|
|
89
|
+
path "CMakeLists.txt"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
lintOptions {
|
|
94
|
+
abortOnError false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
repositories {
|
|
99
|
+
maven {
|
|
100
|
+
url("${reactNativeDir}/android")
|
|
101
|
+
}
|
|
102
|
+
google()
|
|
103
|
+
mavenCentral()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
dependencies {
|
|
107
|
+
implementation "com.facebook.react:react-android"
|
|
108
|
+
// ../cpp/VroomChartHostObject.cpp constructs RN-Skia JSI host objects
|
|
109
|
+
// (JsiSkPicture, etc.) whose base class (RNJsi::JsiHostObject) has
|
|
110
|
+
// out-of-line methods compiled into RN-Skia's own native library — we link
|
|
111
|
+
// against its prefab-published `rnskia` package (below, in CMakeLists.txt)
|
|
112
|
+
// rather than recompiling those .cpp files ourselves, to avoid duplicate
|
|
113
|
+
// definitions of RNSkia's internals across two separately-loaded .so's.
|
|
114
|
+
implementation project(":shopify_react-native-skia")
|
|
115
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// JNI entry point for VroomChartModule.install() (see
|
|
2
|
+
// ../java/com/vroom/chart/VroomChartModule.kt). This is the Android
|
|
3
|
+
// equivalent of ../../ios/VroomChartModule.mm's `-install` method: it
|
|
4
|
+
// reinterprets the JSI runtime pointer handed over from Java and calls the
|
|
5
|
+
// same platform-agnostic vroom::installJsi() the iOS bridge uses.
|
|
6
|
+
|
|
7
|
+
#include <jni.h>
|
|
8
|
+
|
|
9
|
+
#include <jsi/jsi.h>
|
|
10
|
+
|
|
11
|
+
#include "VroomJsiInstaller.h"
|
|
12
|
+
|
|
13
|
+
extern "C" JNIEXPORT jboolean JNICALL
|
|
14
|
+
Java_com_vroom_chart_VroomChartModule_nativeInstall(JNIEnv* /*env*/,
|
|
15
|
+
jobject /*thiz*/,
|
|
16
|
+
jlong runtimePointer) {
|
|
17
|
+
auto* runtime =
|
|
18
|
+
reinterpret_cast<facebook::jsi::Runtime*>(runtimePointer);
|
|
19
|
+
if (runtime == nullptr) {
|
|
20
|
+
return JNI_FALSE;
|
|
21
|
+
}
|
|
22
|
+
vroom::installJsi(*runtime);
|
|
23
|
+
return JNI_TRUE;
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.vroom.chart
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
+
|
|
6
|
+
// TurboModule counterpart to ../../ios/VroomChartModule.mm. `install()` hands
|
|
7
|
+
// the JSI runtime pointer to the native `vroomchart` library (see
|
|
8
|
+
// ../../CMakeLists.txt), which installs `global.VroomChartJSI` via the same
|
|
9
|
+
// platform-agnostic vroom::installJsi() the iOS bridge calls.
|
|
10
|
+
//
|
|
11
|
+
// `NativeVroomChartSpec` is generated by React Native's codegen from
|
|
12
|
+
// ../../../src/NativeVroomChart.ts (codegenConfig.android.javaPackageName in
|
|
13
|
+
// package.json) — the same class name iOS's codegen generates.
|
|
14
|
+
@ReactModule(name = NativeVroomChartSpec.NAME)
|
|
15
|
+
class VroomChartModule(reactContext: ReactApplicationContext) :
|
|
16
|
+
NativeVroomChartSpec(reactContext) {
|
|
17
|
+
|
|
18
|
+
companion object {
|
|
19
|
+
init {
|
|
20
|
+
System.loadLibrary("vroomchart")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private external fun nativeInstall(runtimePointer: Long): Boolean
|
|
25
|
+
|
|
26
|
+
override fun install(): Boolean {
|
|
27
|
+
val runtimePointer =
|
|
28
|
+
reactApplicationContext.javaScriptContextHolder?.get() ?: return false
|
|
29
|
+
return nativeInstall(runtimePointer)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.vroom.chart
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
|
|
9
|
+
class VroomChartPackage : BaseReactPackage() {
|
|
10
|
+
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
|
12
|
+
if (name == NativeVroomChartSpec.NAME) {
|
|
13
|
+
VroomChartModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider {
|
|
19
|
+
mutableMapOf(
|
|
20
|
+
NativeVroomChartSpec.NAME to
|
|
21
|
+
ReactModuleInfo(
|
|
22
|
+
NativeVroomChartSpec.NAME,
|
|
23
|
+
VroomChartModule::class.java.name,
|
|
24
|
+
/* canOverrideExistingModule = */ false,
|
|
25
|
+
/* needsEagerInit = */ false,
|
|
26
|
+
/* isCxxModule = */ false,
|
|
27
|
+
/* isTurboModule = */ true,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|