@onekeyfe/react-native-perp-depth-bar 3.0.53 → 3.0.55
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/PerpDepthBar.podspec +1 -1
- package/README.md +34 -3
- package/android/src/main/java/com/margelo/nitro/perpdepthbar/HybridPerpDepthBars.kt +26 -10
- package/android/src/main/java/com/margelo/nitro/perpdepthbar/HybridPerpSideRatio.kt +11 -5
- package/ios/PerpColorParser.swift +5 -4
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +8 -3
package/PerpDepthBar.podspec
CHANGED
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
13
|
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
-
s.source = { :git => "https://github.com/OneKeyHQ/
|
|
14
|
+
s.source = { :git => "https://github.com/OneKeyHQ/native-views/react-native-perp-depth-bar.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
16
|
s.source_files = [
|
|
17
17
|
"ios/**/*.{swift}",
|
package/README.md
CHANGED
|
@@ -10,12 +10,43 @@ yarn add @onekeyfe/react-native-perp-depth-bar
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
```
|
|
14
|
-
import {
|
|
13
|
+
```tsx
|
|
14
|
+
import { PerpDepthBarsView, PerpSideRatioView } from '@onekeyfe/react-native-perp-depth-bar';
|
|
15
15
|
|
|
16
16
|
// ...
|
|
17
17
|
|
|
18
|
-
<
|
|
18
|
+
<PerpDepthBarsView
|
|
19
|
+
style={{ width: 220, height: 120 }}
|
|
20
|
+
percents={[90, 60, 35]}
|
|
21
|
+
rowHeight={28}
|
|
22
|
+
rowMarginTop={4}
|
|
23
|
+
barInset={2}
|
|
24
|
+
color="rgba(255, 88, 88, 0.18)"
|
|
25
|
+
origin="left"
|
|
26
|
+
reducedMotion={false}
|
|
27
|
+
epoch={0}
|
|
28
|
+
prices={['4100.1', '4099.8', '4099.5']}
|
|
29
|
+
sizes={['1.2', '0.8', '2.4']}
|
|
30
|
+
priceColor="#ff6b6b"
|
|
31
|
+
sizeColor="#8b949e"
|
|
32
|
+
priceFontSize={13}
|
|
33
|
+
sizeFontSize={13}
|
|
34
|
+
textInset={8}
|
|
35
|
+
placeholderText="--"
|
|
36
|
+
placeholderRows={3}
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
<PerpSideRatioView
|
|
40
|
+
style={{ width: 220, height: 4 }}
|
|
41
|
+
bidPercentage={56}
|
|
42
|
+
askPercentage={44}
|
|
43
|
+
longColor="#16a34a"
|
|
44
|
+
shortColor="#dc2626"
|
|
45
|
+
segmentHeight={4}
|
|
46
|
+
cornerRadius={2}
|
|
47
|
+
gap={2}
|
|
48
|
+
reducedMotion={false}
|
|
49
|
+
/>
|
|
19
50
|
```
|
|
20
51
|
|
|
21
52
|
## Contributing
|
|
@@ -231,12 +231,23 @@ class HybridPerpDepthBars(val context: ThemedReactContext) : HybridPerpDepthBars
|
|
|
231
231
|
*/
|
|
232
232
|
override fun setDepth(buffer: ArrayBuffer) {
|
|
233
233
|
if (isDisposed) return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
// Parse the foreign JS buffer synchronously on the calling (JS) thread into a
|
|
235
|
+
// local copy, BEFORE hopping to the UI thread. `getBuffer(true)` requests a
|
|
236
|
+
// copy so the bytes can't be reclaimed/overwritten once this call returns, and
|
|
237
|
+
// reads are clamped to `remaining()` rather than assuming a position-0,
|
|
238
|
+
// capacity==size buffer (a sub-view buffer would otherwise IndexOutOfBounds).
|
|
239
|
+
val floats = buffer.getBuffer(true).order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer()
|
|
240
|
+
val count = floats.remaining()
|
|
241
|
+
// Relative reads honour `remaining()` from the buffer's current position, so a
|
|
242
|
+
// sub-view (position != 0, capacity > size) is read correctly, not from index 0.
|
|
243
|
+
val depths = DoubleArray(count) { floats.get().toDouble() }
|
|
244
|
+
// Shared drawing state (current/target, invalidate, Choreographer) is mutated
|
|
245
|
+
// only on the UI thread; `onFrame` reads/writes the same state there.
|
|
246
|
+
view.post {
|
|
247
|
+
if (isDisposed) return@post
|
|
248
|
+
imperativeDepth = true
|
|
249
|
+
syncTargets(depths)
|
|
250
|
+
}
|
|
240
251
|
}
|
|
241
252
|
|
|
242
253
|
/**
|
|
@@ -248,10 +259,15 @@ class HybridPerpDepthBars(val context: ThemedReactContext) : HybridPerpDepthBars
|
|
|
248
259
|
*/
|
|
249
260
|
override fun setText(prices: Array<String>, sizes: Array<String>) {
|
|
250
261
|
if (isDisposed) return
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
262
|
+
// Mutate the drawn strings + invalidate on the UI thread; `drawTexts` reads
|
|
263
|
+
// them there. The args are read synchronously on the calling (JS) thread.
|
|
264
|
+
view.post {
|
|
265
|
+
if (isDisposed) return@post
|
|
266
|
+
imperativeText = true
|
|
267
|
+
displayPrices = prices
|
|
268
|
+
displaySizes = sizes
|
|
269
|
+
view.invalidate()
|
|
270
|
+
}
|
|
255
271
|
}
|
|
256
272
|
|
|
257
273
|
private fun syncTargets(depths: DoubleArray) {
|
|
@@ -103,11 +103,17 @@ class HybridPerpSideRatio(val context: ThemedReactContext) : HybridPerpSideRatio
|
|
|
103
103
|
*/
|
|
104
104
|
override fun setRatio(bidPercentage: Double, askPercentage: Double) {
|
|
105
105
|
if (isDisposed) return
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
// The args are read synchronously on the calling (JS) thread; the shared
|
|
107
|
+
// drawing state (currentSplit/targetSplit, invalidate, Choreographer) is
|
|
108
|
+
// mutated only on the UI thread, where `onFrame` reads/writes the same state.
|
|
109
|
+
view.post {
|
|
110
|
+
if (isDisposed) return@post
|
|
111
|
+
imperativeRatio = true
|
|
112
|
+
// Apply the args directly — do NOT route through the `bidPercentage`/
|
|
113
|
+
// `askPercentage` prop fields, which a later prop commit could overwrite with
|
|
114
|
+
// the static initial values.
|
|
115
|
+
applyRatio(bidPercentage, askPercentage)
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
override fun afterUpdate() {
|
|
@@ -61,11 +61,12 @@ enum PerpColorParser {
|
|
|
61
61
|
let g = Double(parts[1]),
|
|
62
62
|
let b = Double(parts[2]) else { return nil }
|
|
63
63
|
let a = parts.count >= 4 ? (Double(parts[3]) ?? 1.0) : 1.0
|
|
64
|
+
// Clamp channels to 0...255 and alpha to 0...1 (matches Android's PerpColorParser).
|
|
64
65
|
return UIColor(
|
|
65
|
-
red: CGFloat(r) / 255.0,
|
|
66
|
-
green: CGFloat(g) / 255.0,
|
|
67
|
-
blue: CGFloat(b) / 255.0,
|
|
68
|
-
alpha: CGFloat(a)
|
|
66
|
+
red: CGFloat(min(max(r, 0), 255)) / 255.0,
|
|
67
|
+
green: CGFloat(min(max(g, 0), 255)) / 255.0,
|
|
68
|
+
blue: CGFloat(min(max(b, 0), 255)) / 255.0,
|
|
69
|
+
alpha: CGFloat(min(max(a, 0), 1))
|
|
69
70
|
)
|
|
70
71
|
}
|
|
71
72
|
}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useCallback, useRef } from 'react';
|
|
3
|
+
import { useCallback, useMemo, useRef } from 'react';
|
|
4
4
|
import { callback, getHostComponent } from 'react-native-nitro-modules';
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
const PerpDepthBarsConfig = require('../nitrogen/generated/shared/json/PerpDepthBarsConfig.json');
|
|
@@ -22,9 +22,10 @@ export function PerpDepthBarsView({
|
|
|
22
22
|
const stableOnRowPress = useCallback(rowIndex => {
|
|
23
23
|
onRowPressRef.current?.(rowIndex);
|
|
24
24
|
}, []);
|
|
25
|
+
const onRowPressCallback = useMemo(() => callback(stableOnRowPress), [stableOnRowPress]);
|
|
25
26
|
return /*#__PURE__*/_jsx(PerpDepthBarsHost, {
|
|
26
27
|
...props,
|
|
27
|
-
onRowPress: onRowPress ?
|
|
28
|
+
onRowPress: onRowPress ? onRowPressCallback : undefined
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
export const PerpSideRatioView = getHostComponent('PerpSideRatio', () => PerpSideRatioConfig);
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useRef","callback","getHostComponent","jsx","_jsx","PerpDepthBarsConfig","require","PerpSideRatioConfig","PerpDepthBarsHost","PerpDepthBarsView","onRowPress","props","onRowPressRef","current","stableOnRowPress","rowIndex","undefined","PerpSideRatioView"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"names":["useCallback","useMemo","useRef","callback","getHostComponent","jsx","_jsx","PerpDepthBarsConfig","require","PerpSideRatioConfig","PerpDepthBarsHost","PerpDepthBarsView","onRowPress","props","onRowPressRef","current","stableOnRowPress","rowIndex","onRowPressCallback","undefined","PerpSideRatioView"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAEpD,SAASC,QAAQ,EAAEC,gBAAgB,QAAQ,4BAA4B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAWxE,MAAMC,mBAAmB,GAAGC,OAAO,CAAC,4DAA4D,CAAC;AACjG,MAAMC,mBAAmB,GAAGD,OAAO,CAAC,4DAA4D,CAAC;AASjG,MAAME,iBAAiB,GAAGN,gBAAgB,CAGxC,eAAe,EAAE,MAAMG,mBAAmB,CAAC;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,iBAAiBA,CAAC;EAChCC,UAAU;EACV,GAAGC;AAC2B,CAAC,EAAE;EACjC,MAAMC,aAAa,GAAGZ,MAAM,CAACU,UAAU,CAAC;EACxCE,aAAa,CAACC,OAAO,GAAGH,UAAU;EAElC,MAAMI,gBAAgB,GAAGhB,WAAW,CAAEiB,QAAgB,IAAK;IACzDH,aAAa,CAACC,OAAO,GAAGE,QAAQ,CAAC;EACnC,CAAC,EAAE,EAAE,CAAC;EACN,MAAMC,kBAAkB,GAAGjB,OAAO,CAChC,MAAME,QAAQ,CAACa,gBAAgB,CAAC,EAChC,CAACA,gBAAgB,CACnB,CAAC;EAED,oBACEV,IAAA,CAACI,iBAAiB;IAAA,GACZG,KAAK;IACTD,UAAU,EAAEA,UAAU,GAAGM,kBAAkB,GAAGC;EAAU,CACzD,CAAC;AAEN;AAEA,OAAO,MAAMC,iBAAiB,GAAGhB,gBAAgB,CAG/C,eAAe,EAAE,MAAMK,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
1
2
|
import type { PerpDepthBarsMethods, PerpDepthBarsProps } from './PerpDepthBars.nitro';
|
|
2
3
|
import type { PerpSideRatioMethods, PerpSideRatioProps } from './PerpSideRatio.nitro';
|
|
3
4
|
export type { PerpDepthBarsMethods, PerpDepthBarsProps, PerpSideRatioMethods, PerpSideRatioProps, };
|
|
@@ -7,6 +8,6 @@ export type { PerpDepthBarsMethods, PerpDepthBarsProps, PerpSideRatioMethods, Pe
|
|
|
7
8
|
* we encapsulate that here (with a ref so the underlying callback stays
|
|
8
9
|
* stable across re-renders) instead of leaking it to every call site.
|
|
9
10
|
*/
|
|
10
|
-
export declare function PerpDepthBarsView({ onRowPress, ...props }: PerpDepthBarsProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function PerpDepthBarsView({ onRowPress, ...props }: PerpDepthBarsProps & ViewProps): import("react/jsx-runtime").JSX.Element;
|
|
11
12
|
export declare const PerpSideRatioView: import("react-native-nitro-modules").ReactNativeView<PerpSideRatioProps, PerpSideRatioMethods>;
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAK/B,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,GACnB,CAAC;AAOF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,UAAU,EACV,GAAG,KAAK,EACT,EAAE,kBAAkB,GAAG,SAAS,2CAkBhC;AAED,eAAO,MAAM,iBAAiB,gGAGe,CAAC"}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useCallback, useRef } from 'react';
|
|
1
|
+
import { useCallback, useMemo, useRef } from 'react';
|
|
2
|
+
import { type ViewProps } from 'react-native';
|
|
2
3
|
import { callback, getHostComponent } from 'react-native-nitro-modules';
|
|
3
4
|
|
|
4
5
|
import type {
|
|
@@ -34,18 +35,22 @@ const PerpDepthBarsHost = getHostComponent<
|
|
|
34
35
|
export function PerpDepthBarsView({
|
|
35
36
|
onRowPress,
|
|
36
37
|
...props
|
|
37
|
-
}: PerpDepthBarsProps) {
|
|
38
|
+
}: PerpDepthBarsProps & ViewProps) {
|
|
38
39
|
const onRowPressRef = useRef(onRowPress);
|
|
39
40
|
onRowPressRef.current = onRowPress;
|
|
40
41
|
|
|
41
42
|
const stableOnRowPress = useCallback((rowIndex: number) => {
|
|
42
43
|
onRowPressRef.current?.(rowIndex);
|
|
43
44
|
}, []);
|
|
45
|
+
const onRowPressCallback = useMemo(
|
|
46
|
+
() => callback(stableOnRowPress),
|
|
47
|
+
[stableOnRowPress],
|
|
48
|
+
);
|
|
44
49
|
|
|
45
50
|
return (
|
|
46
51
|
<PerpDepthBarsHost
|
|
47
52
|
{...props}
|
|
48
|
-
onRowPress={onRowPress ?
|
|
53
|
+
onRowPress={onRowPress ? onRowPressCallback : undefined}
|
|
49
54
|
/>
|
|
50
55
|
);
|
|
51
56
|
}
|