react-native-morph-card 0.2.8 → 0.3.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/README.md +4 -4
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardSourceView.kt +5 -1
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardTargetView.kt +25 -1
- package/ios/Fabric/RNCMorphCardSourceComponentView.mm +15 -1
- package/ios/Fabric/RNCMorphCardTargetComponentView.h +1 -0
- package/ios/Fabric/RNCMorphCardTargetComponentView.mm +21 -0
- package/lib/commonjs/MorphCardSource.js +25 -2
- package/lib/commonjs/MorphCardSource.js.map +1 -1
- package/lib/commonjs/MorphCardTarget.js +31 -7
- package/lib/commonjs/MorphCardTarget.js.map +1 -1
- package/lib/commonjs/MorphChildrenRegistry.js +34 -0
- package/lib/commonjs/MorphChildrenRegistry.js.map +1 -0
- package/lib/module/MorphCardSource.js +25 -2
- package/lib/module/MorphCardSource.js.map +1 -1
- package/lib/module/MorphCardTarget.js +31 -7
- package/lib/module/MorphCardTarget.js.map +1 -1
- package/lib/module/MorphChildrenRegistry.js +27 -0
- package/lib/module/MorphChildrenRegistry.js.map +1 -0
- package/lib/typescript/src/MorphCardSource.d.ts +4 -4
- package/lib/typescript/src/MorphCardSource.d.ts.map +1 -1
- package/lib/typescript/src/MorphCardTarget.d.ts.map +1 -1
- package/lib/typescript/src/MorphChildrenRegistry.d.ts +13 -0
- package/lib/typescript/src/MorphChildrenRegistry.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MorphCardSource.tsx +27 -5
- package/src/MorphCardTarget.tsx +44 -9
- package/src/MorphChildrenRegistry.ts +43 -0
- package/src/index.tsx +1 -1
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ No additional steps required.
|
|
|
46
46
|
|
|
47
47
|
Wrap your card content in `MorphCardSource`. On the detail screen, use `MorphCardTarget` where the card should land. Use `useMorphTarget` for easy collapse handling.
|
|
48
48
|
|
|
49
|
-
> **Important:** `MorphCardSource` can wrap any React Native component (images, views, text, etc.)
|
|
49
|
+
> **Important:** `MorphCardSource` can wrap any React Native component (images, views, text, etc.). During the animation, the content is captured as a **bitmap snapshot** — but once the animation completes, the snapshot fades out and the source's children are automatically cloned into `MorphCardTarget` as live React components. The cloned children are rendered at the source card's original layout dimensions, so your component layout stays consistent. This means observable values (timers, animated values, live data) will update in real time after the transition finishes. If you use `resizeMode`, the bitmap is kept instead (native image scaling doesn't apply to React components).
|
|
50
50
|
|
|
51
51
|
```tsx
|
|
52
52
|
import React from 'react';
|
|
@@ -110,12 +110,12 @@ Wraps the card content on the list/grid screen. Captures a snapshot and drives t
|
|
|
110
110
|
| `backgroundColor` | `string` | — | Background color (enables "wrapper mode" where the background expands separately from the content) |
|
|
111
111
|
| `duration` | `number` | `300` | Default animation duration in ms (used for both expand and collapse if specific durations are not set) |
|
|
112
112
|
| `expandDuration` | `number` | — | Duration of the expand animation in ms. Overrides `duration` for expand. |
|
|
113
|
-
| `
|
|
113
|
+
| `resizeMode` | `'cover' \| 'contain' \| 'stretch'` | `'cover'` | How the snapshot scales during animation. When set, the bitmap is kept after expand (no live children). **Recommended when wrapping an `<Image>` — without it, the image may not scale properly during the animation.** |
|
|
114
114
|
| `onPress` | `(sourceTag: number) => void` | — | Called on tap with the native view tag. Use this to navigate to the detail screen. |
|
|
115
115
|
|
|
116
116
|
### `<MorphCardTarget>`
|
|
117
117
|
|
|
118
|
-
Placed on the detail screen where the card should land. Triggers the expand animation on mount.
|
|
118
|
+
Placed on the detail screen where the card should land. Triggers the expand animation on mount. After the animation, the source's children are automatically cloned here as live React components.
|
|
119
119
|
|
|
120
120
|
| Prop | Type | Default | Description |
|
|
121
121
|
| ------------------ | ---------------- | ------------- | -------------------------------------------------------------------------------- |
|
|
@@ -161,7 +161,7 @@ await morphCollapse(sourceTag);
|
|
|
161
161
|
const tag = getViewTag(viewRef);
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
```
|
|
165
165
|
|
|
166
166
|
## Running the example app
|
|
167
167
|
|
|
@@ -655,6 +655,8 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
655
655
|
|
|
656
656
|
target.showSnapshot(bitmap, frame, cornerRadius, null)
|
|
657
657
|
Log.d(TAG, "transferSnapshot: handed snapshot to MorphCardTargetView")
|
|
658
|
+
// Crossfade snapshot out to reveal live React children underneath
|
|
659
|
+
mainHandler.postDelayed({ target.fadeOutSnapshot() }, 50)
|
|
658
660
|
}
|
|
659
661
|
|
|
660
662
|
val fadeOut = ValueAnimator.ofFloat(1f, 0f)
|
|
@@ -726,8 +728,10 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
726
728
|
val cardImage = captureSnapshot()
|
|
727
729
|
alpha = 0f
|
|
728
730
|
|
|
729
|
-
// Clear the snapshot
|
|
731
|
+
// Clear the snapshot and hide the target view so live children
|
|
732
|
+
// don't show behind the animating collapse overlay
|
|
730
733
|
target?.clearSnapshot()
|
|
734
|
+
targetView?.visibility = View.INVISIBLE
|
|
731
735
|
|
|
732
736
|
wrapper = FrameLayout(context)
|
|
733
737
|
wrapper.layoutParams = FrameLayout.LayoutParams(twPx.toInt(), thPx.toInt())
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.melivalesca.morphcard
|
|
2
2
|
|
|
3
|
+
import android.animation.ValueAnimator
|
|
3
4
|
import android.content.Context
|
|
4
5
|
import android.graphics.Bitmap
|
|
5
6
|
import android.graphics.Canvas
|
|
@@ -21,6 +22,7 @@ class MorphCardTargetView(context: Context) : ReactViewGroup(context) {
|
|
|
21
22
|
private var snapshotFrame: RectF? = null
|
|
22
23
|
private var snapshotCornerRadius: Float = 0f
|
|
23
24
|
private var snapshotBgColor: Int? = null
|
|
25
|
+
private var snapshotAlpha: Float = 1f
|
|
24
26
|
private val snapshotPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
|
|
25
27
|
private val bgPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
26
28
|
|
|
@@ -58,7 +60,9 @@ class MorphCardTargetView(context: Context) : ReactViewGroup(context) {
|
|
|
58
60
|
override fun dispatchDraw(canvas: Canvas) {
|
|
59
61
|
val bmp = snapshotBitmap
|
|
60
62
|
val frame = snapshotFrame
|
|
61
|
-
if (bmp != null && frame != null) {
|
|
63
|
+
if (bmp != null && frame != null && snapshotAlpha > 0f) {
|
|
64
|
+
snapshotPaint.alpha = (snapshotAlpha * 255).toInt()
|
|
65
|
+
bgPaint.alpha = (snapshotAlpha * 255).toInt()
|
|
62
66
|
val radiusPx = snapshotCornerRadius
|
|
63
67
|
|
|
64
68
|
// Clip to rounded rect if needed
|
|
@@ -114,6 +118,26 @@ class MorphCardTargetView(context: Context) : ReactViewGroup(context) {
|
|
|
114
118
|
invalidate()
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
fun fadeOutSnapshot() {
|
|
122
|
+
if (snapshotBitmap == null) return
|
|
123
|
+
// Only fade out if there are React children underneath to reveal.
|
|
124
|
+
// If no children (scaleMode bitmap-only), keep the snapshot.
|
|
125
|
+
if (childCount == 0) return
|
|
126
|
+
val anim = ValueAnimator.ofFloat(1f, 0f)
|
|
127
|
+
anim.duration = 150
|
|
128
|
+
anim.addUpdateListener {
|
|
129
|
+
snapshotAlpha = it.animatedValue as Float
|
|
130
|
+
invalidate()
|
|
131
|
+
}
|
|
132
|
+
anim.addListener(object : android.animation.AnimatorListenerAdapter() {
|
|
133
|
+
override fun onAnimationEnd(animation: android.animation.Animator) {
|
|
134
|
+
clearSnapshot()
|
|
135
|
+
snapshotAlpha = 1f
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
anim.start()
|
|
139
|
+
}
|
|
140
|
+
|
|
117
141
|
fun clearSnapshot() {
|
|
118
142
|
if (snapshotBitmap != null) {
|
|
119
143
|
Log.d(TAG, "clearSnapshot: clearing bitmap")
|
|
@@ -338,6 +338,12 @@ static CGRect imageFrameForScaleMode(UIViewContentMode mode,
|
|
|
338
338
|
cornerRadius:targetCornerRadius
|
|
339
339
|
backgroundColor:wrapperBg];
|
|
340
340
|
}
|
|
341
|
+
// Crossfade snapshot out to reveal live React children underneath
|
|
342
|
+
dispatch_after(
|
|
343
|
+
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)),
|
|
344
|
+
dispatch_get_main_queue(), ^{
|
|
345
|
+
[target fadeOutSnapshot];
|
|
346
|
+
});
|
|
341
347
|
}
|
|
342
348
|
if (targetView) { targetView.hidden = NO; }
|
|
343
349
|
self.alpha = 1;
|
|
@@ -414,6 +420,12 @@ static CGRect imageFrameForScaleMode(UIViewContentMode mode,
|
|
|
414
420
|
frame:target.bounds
|
|
415
421
|
cornerRadius:targetCornerRadius
|
|
416
422
|
backgroundColor:nil];
|
|
423
|
+
// Crossfade snapshot out to reveal live React children underneath
|
|
424
|
+
dispatch_after(
|
|
425
|
+
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)),
|
|
426
|
+
dispatch_get_main_queue(), ^{
|
|
427
|
+
[target fadeOutSnapshot];
|
|
428
|
+
});
|
|
417
429
|
}
|
|
418
430
|
if (targetView) { targetView.hidden = NO; }
|
|
419
431
|
self.alpha = 1;
|
|
@@ -447,9 +459,11 @@ static CGRect imageFrameForScaleMode(UIViewContentMode mode,
|
|
|
447
459
|
UIView *targetScreen = _targetScreenContainer;
|
|
448
460
|
UIView *sourceScreen = _sourceScreenContainer;
|
|
449
461
|
|
|
450
|
-
// Clear the snapshot
|
|
462
|
+
// Clear the snapshot and hide the target view so live children
|
|
463
|
+
// don't show behind the animating collapse overlay
|
|
451
464
|
if (targetView && [targetView isKindOfClass:[RNCMorphCardTargetComponentView class]]) {
|
|
452
465
|
[(RNCMorphCardTargetComponentView *)targetView clearSnapshot];
|
|
466
|
+
targetView.hidden = YES;
|
|
453
467
|
}
|
|
454
468
|
|
|
455
469
|
CGFloat collapseDur = 0;
|
|
@@ -72,6 +72,27 @@ extern UIView *RNCMorphCardFindScreenContainer(UIView *view);
|
|
|
72
72
|
_snapshotContainer = container;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
- (void)fadeOutSnapshot {
|
|
76
|
+
UIView *snap = _snapshotContainer;
|
|
77
|
+
if (!snap) return;
|
|
78
|
+
// Only fade out if there are React children underneath to reveal.
|
|
79
|
+
// If no children (scaleMode bitmap-only), keep the snapshot.
|
|
80
|
+
BOOL hasReactChildren = NO;
|
|
81
|
+
for (UIView *child in self.subviews) {
|
|
82
|
+
if (child != _snapshotContainer) { hasReactChildren = YES; break; }
|
|
83
|
+
}
|
|
84
|
+
if (!hasReactChildren) return;
|
|
85
|
+
|
|
86
|
+
[UIView animateWithDuration:0.15
|
|
87
|
+
animations:^{ snap.alpha = 0; }
|
|
88
|
+
completion:^(BOOL finished) {
|
|
89
|
+
[snap removeFromSuperview];
|
|
90
|
+
if (self->_snapshotContainer == snap) {
|
|
91
|
+
self->_snapshotContainer = nil;
|
|
92
|
+
}
|
|
93
|
+
}];
|
|
94
|
+
}
|
|
95
|
+
|
|
75
96
|
- (void)clearSnapshot {
|
|
76
97
|
if (_snapshotContainer) {
|
|
77
98
|
[_snapshotContainer removeFromSuperview];
|
|
@@ -11,6 +11,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _reactNative = require("react-native");
|
|
12
12
|
var _NativeMorphCardModule = _interopRequireDefault(require("./specs/NativeMorphCardModule"));
|
|
13
13
|
var _NativeMorphCardSource = _interopRequireDefault(require("./specs/NativeMorphCardSource"));
|
|
14
|
+
var _MorphChildrenRegistry = require("./MorphChildrenRegistry");
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
17
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -23,12 +24,23 @@ const MorphCardSource = ({
|
|
|
23
24
|
height,
|
|
24
25
|
borderRadius,
|
|
25
26
|
backgroundColor,
|
|
26
|
-
|
|
27
|
+
resizeMode,
|
|
27
28
|
onPress,
|
|
28
29
|
ref
|
|
29
30
|
}) => {
|
|
30
31
|
const nativeRef = React.useRef(null);
|
|
31
32
|
React.useImperativeHandle(ref, () => nativeRef.current);
|
|
33
|
+
|
|
34
|
+
// Store children in shared registry so MorphCardTarget can clone them
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const tag = (0, _reactNative.findNodeHandle)(nativeRef.current);
|
|
37
|
+
if (tag != null) {
|
|
38
|
+
(0, _MorphChildrenRegistry.setSourceEntry)(tag, children, backgroundColor, resizeMode);
|
|
39
|
+
}
|
|
40
|
+
return () => {
|
|
41
|
+
if (tag != null) (0, _MorphChildrenRegistry.clearSourceEntry)(tag);
|
|
42
|
+
};
|
|
43
|
+
}, [children, backgroundColor, resizeMode]);
|
|
32
44
|
const style = {};
|
|
33
45
|
if (width != null) style.width = width;
|
|
34
46
|
if (height != null) style.height = height;
|
|
@@ -37,6 +49,16 @@ const MorphCardSource = ({
|
|
|
37
49
|
style.overflow = 'hidden';
|
|
38
50
|
}
|
|
39
51
|
if (backgroundColor != null) style.backgroundColor = backgroundColor;
|
|
52
|
+
const handleLayout = React.useCallback(e => {
|
|
53
|
+
const tag = (0, _reactNative.findNodeHandle)(nativeRef.current);
|
|
54
|
+
if (tag != null) {
|
|
55
|
+
const {
|
|
56
|
+
width: lw,
|
|
57
|
+
height: lh
|
|
58
|
+
} = e.nativeEvent.layout;
|
|
59
|
+
(0, _MorphChildrenRegistry.setSourceLayout)(tag, lw, lh);
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
40
62
|
const handlePress = React.useCallback(() => {
|
|
41
63
|
if (!onPress) return;
|
|
42
64
|
const tag = (0, _reactNative.findNodeHandle)(nativeRef.current);
|
|
@@ -52,9 +74,10 @@ const MorphCardSource = ({
|
|
|
52
74
|
ref: nativeRef,
|
|
53
75
|
duration: duration,
|
|
54
76
|
expandDuration: expandDuration,
|
|
55
|
-
scaleMode:
|
|
77
|
+
scaleMode: resizeMode === 'contain' ? 'aspectFit' : resizeMode === 'stretch' ? 'stretch' : 'aspectFill',
|
|
56
78
|
cardBorderRadius: borderRadius,
|
|
57
79
|
style: style,
|
|
80
|
+
onLayout: handleLayout,
|
|
58
81
|
children: children
|
|
59
82
|
});
|
|
60
83
|
if (onPress) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_NativeMorphCardModule","_interopRequireDefault","_NativeMorphCardSource","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NativeSourceView","NativeSourceViewSpec","View","MorphCardSource","children","duration","expandDuration","width","height","borderRadius","backgroundColor","
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_NativeMorphCardModule","_interopRequireDefault","_NativeMorphCardSource","_MorphChildrenRegistry","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NativeSourceView","NativeSourceViewSpec","View","MorphCardSource","children","duration","expandDuration","width","height","borderRadius","backgroundColor","resizeMode","onPress","ref","nativeRef","useRef","useImperativeHandle","current","useEffect","tag","findNodeHandle","setSourceEntry","clearSourceEntry","style","overflow","handleLayout","useCallback","lw","lh","nativeEvent","layout","setSourceLayout","handlePress","NativeMorphCardModule","prepareExpand","requestAnimationFrame","content","jsx","scaleMode","cardBorderRadius","onLayout","Pressable","exports","getViewTag","viewRef","morphExpand","sourceRef","targetRef","sourceTag","targetTag","expand","morphCollapse","collapse"],"sourceRoot":"../../src","sources":["MorphCardSource.tsx"],"mappings":";;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAQA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAA4F,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAG,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,CAAAQ,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IA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GAAG,WAAW,GAAGA,UAAU,KAAK,SAAS,GAAG,SAAS,GAAG,YAAa;IAAC4B,gBAAgB,EAAE9B,YAAa;IAACc,KAAK,EAAEA,KAAM;IAACiB,QAAQ,EAAEf,YAAa;IAAArB,QAAA,EACjQA;EAAQ,CACO,CACnB;EAED,IAAIQ,OAAO,EAAE;IACX,oBAAO,IAAAhC,WAAA,CAAAyD,GAAA,EAAC9D,YAAA,CAAAkE,SAAS;MAAC7B,OAAO,EAAEoB,WAAY;MAAA5B,QAAA,EAAEgC;IAAO,CAAY,CAAC;EAC/D;EAEA,OAAOA,OAAO;AAChB,CAAC;;AAED;AACA;AACA;AACA;AAHAM,OAAA,CAAAvC,eAAA,GAAAA,eAAA;AAIO,SAASwC,UAAUA,CAACC,OAA6B,EAAiB;EACvE,OAAO,IAAAxB,2BAAc,EAACwB,OAAO,CAAC3B,OAAO,CAAC;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe4B,WAAWA,CAC/BC,SAA+B,EAC/BC,SAA+B,EACb;EAClB,MAAMC,SAAS,GAAG,IAAA5B,2BAAc,EAAC0B,SAAS,CAAC7B,OAAO,CAAC;EACnD,MAAMgC,SAAS,GAAG,IAAA7B,2BAAc,EAAC2B,SAAS,CAAC9B,OAAO,CAAC;EACnD,IAAI,CAAC+B,SAAS,IAAI,CAACC,SAAS,EAAE,OAAO,KAAK;EAC1C,OAAOhB,8BAAqB,CAACiB,MAAM,CAACF,SAAS,EAAEC,SAAS,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACO,eAAeE,aAAaA,CAACH,SAAiB,EAAoB;EACvE,OAAOf,8BAAqB,CAACmB,QAAQ,CAACJ,SAAS,CAAC;AAClD","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _NativeMorphCardModule = _interopRequireDefault(require("./specs/NativeMorphCardModule"));
|
|
10
10
|
var _NativeMorphCardTarget = _interopRequireDefault(require("./specs/NativeMorphCardTarget"));
|
|
11
|
+
var _MorphChildrenRegistry = require("./MorphChildrenRegistry");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -52,16 +53,32 @@ const MorphCardTarget = ({
|
|
|
52
53
|
_NativeMorphCardModule.default.setTargetConfig(sourceTag, lw, lh, borderRadius != null ? borderRadius : -1, contentOffsetY ?? 0, contentCentered ?? false);
|
|
53
54
|
_NativeMorphCardModule.default.expand(sourceTag, targetTag);
|
|
54
55
|
}, [sourceTag, borderRadius, contentOffsetY, contentCentered]);
|
|
55
|
-
const
|
|
56
|
+
const sourceEntry = (0, _MorphChildrenRegistry.getSourceEntry)(sourceTag);
|
|
57
|
+
const containerStyle = {
|
|
58
|
+
overflow: 'hidden'
|
|
59
|
+
};
|
|
60
|
+
if (sourceEntry?.backgroundColor) {
|
|
61
|
+
containerStyle.backgroundColor = sourceEntry.backgroundColor;
|
|
62
|
+
}
|
|
63
|
+
if (contentCentered) {
|
|
64
|
+
containerStyle.justifyContent = 'center';
|
|
65
|
+
containerStyle.alignItems = 'center';
|
|
66
|
+
}
|
|
67
|
+
if (contentOffsetY) {
|
|
68
|
+
containerStyle.paddingTop = contentOffsetY;
|
|
69
|
+
}
|
|
56
70
|
if (width != null) {
|
|
57
|
-
|
|
71
|
+
containerStyle.width = width;
|
|
58
72
|
} else if (sourceSize) {
|
|
59
|
-
|
|
73
|
+
containerStyle.width = sourceSize.width;
|
|
60
74
|
}
|
|
61
75
|
if (height != null) {
|
|
62
|
-
|
|
76
|
+
containerStyle.height = height;
|
|
63
77
|
} else if (sourceSize) {
|
|
64
|
-
|
|
78
|
+
containerStyle.height = sourceSize.height;
|
|
79
|
+
}
|
|
80
|
+
if (borderRadius) {
|
|
81
|
+
containerStyle.borderRadius = borderRadius;
|
|
65
82
|
}
|
|
66
83
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(NativeTargetView, {
|
|
67
84
|
ref: nativeRef,
|
|
@@ -70,8 +87,15 @@ const MorphCardTarget = ({
|
|
|
70
87
|
targetWidth: 0,
|
|
71
88
|
targetHeight: 0,
|
|
72
89
|
targetBorderRadius: borderRadius != null ? borderRadius : -1,
|
|
73
|
-
style:
|
|
74
|
-
onLayout: handleLayout
|
|
90
|
+
style: containerStyle,
|
|
91
|
+
onLayout: handleLayout,
|
|
92
|
+
children: sourceEntry && !sourceEntry.scaleMode && (sourceEntry.backgroundColor && sourceEntry.layoutWidth ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
93
|
+
style: {
|
|
94
|
+
width: sourceEntry.layoutWidth,
|
|
95
|
+
height: sourceEntry.layoutHeight
|
|
96
|
+
},
|
|
97
|
+
children: sourceEntry.children
|
|
98
|
+
}) : sourceEntry.children)
|
|
75
99
|
});
|
|
76
100
|
};
|
|
77
101
|
exports.MorphCardTarget = MorphCardTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_NativeMorphCardModule","_interopRequireDefault","_NativeMorphCardTarget","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NativeTargetView","NativeTargetViewSpec","View","MorphCardTarget","sourceTag","collapseDuration","width","height","borderRadius","contentOffsetY","contentCentered","nativeRef","useRef","expandedRef","sourceSize","setSourceSize","useState","useEffect","cancelled","NativeMorphCardModule","getSourceSize","then","size","catch","handleLayout","useCallback","current","lw","lh","nativeEvent","layout","targetTag","findNodeHandle","setTargetConfig","expand","
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_NativeMorphCardModule","_interopRequireDefault","_NativeMorphCardTarget","_MorphChildrenRegistry","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NativeTargetView","NativeTargetViewSpec","View","MorphCardTarget","sourceTag","collapseDuration","width","height","borderRadius","contentOffsetY","contentCentered","nativeRef","useRef","expandedRef","sourceSize","setSourceSize","useState","useEffect","cancelled","NativeMorphCardModule","getSourceSize","then","size","catch","handleLayout","useCallback","current","lw","lh","nativeEvent","layout","targetTag","findNodeHandle","setTargetConfig","expand","sourceEntry","getSourceEntry","containerStyle","overflow","backgroundColor","justifyContent","alignItems","paddingTop","jsx","ref","targetWidth","targetHeight","targetBorderRadius","style","onLayout","children","scaleMode","layoutWidth","layoutHeight","exports"],"sourceRoot":"../../src","sources":["MorphCardTarget.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAAyD,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAG,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAA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,CAACgB,SAAS,KACrBhB,WAAW,CAACI,eAAe,IAAIJ,WAAW,CAACiB,WAAW,gBACrD,IAAAxE,WAAA,CAAA+D,GAAA,EAACpE,YAAA,CAAA2B,IAAI;MACH8C,KAAK,EAAE;QACL1C,KAAK,EAAE6B,WAAW,CAACiB,WAAW;QAC9B7C,MAAM,EAAE4B,WAAW,CAACkB;MACtB,CAAE;MAAAH,QAAA,EAEDf,WAAW,CAACe;IAAQ,CACjB,CAAC,GAEPf,WAAW,CAACe,QACb;EAAC,CACY,CAAC;AAEvB,CAAC;AAACI,OAAA,CAAAnD,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearSourceEntry = clearSourceEntry;
|
|
7
|
+
exports.getSourceEntry = getSourceEntry;
|
|
8
|
+
exports.setSourceEntry = setSourceEntry;
|
|
9
|
+
exports.setSourceLayout = setSourceLayout;
|
|
10
|
+
const registry = new Map();
|
|
11
|
+
function setSourceEntry(tag, children, backgroundColor, scaleMode) {
|
|
12
|
+
const existing = registry.get(tag);
|
|
13
|
+
registry.set(tag, {
|
|
14
|
+
children,
|
|
15
|
+
backgroundColor,
|
|
16
|
+
scaleMode,
|
|
17
|
+
layoutWidth: existing?.layoutWidth,
|
|
18
|
+
layoutHeight: existing?.layoutHeight
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function setSourceLayout(tag, width, height) {
|
|
22
|
+
const existing = registry.get(tag);
|
|
23
|
+
if (existing) {
|
|
24
|
+
existing.layoutWidth = width;
|
|
25
|
+
existing.layoutHeight = height;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getSourceEntry(tag) {
|
|
29
|
+
return registry.get(tag);
|
|
30
|
+
}
|
|
31
|
+
function clearSourceEntry(tag) {
|
|
32
|
+
registry.delete(tag);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=MorphChildrenRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","Map","setSourceEntry","tag","children","backgroundColor","scaleMode","existing","get","set","layoutWidth","layoutHeight","setSourceLayout","width","height","getSourceEntry","clearSourceEntry","delete"],"sourceRoot":"../../src","sources":["MorphChildrenRegistry.ts"],"mappings":";;;;;;;;;AAUA,MAAMA,QAAQ,GAAG,IAAIC,GAAG,CAAsB,CAAC;AAExC,SAASC,cAAcA,CAC5BC,GAAW,EACXC,QAAmB,EACnBC,eAAwB,EACxBC,SAAkB,EAClB;EACA,MAAMC,QAAQ,GAAGP,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;EAClCH,QAAQ,CAACS,GAAG,CAACN,GAAG,EAAE;IAChBC,QAAQ;IACRC,eAAe;IACfC,SAAS;IACTI,WAAW,EAAEH,QAAQ,EAAEG,WAAW;IAClCC,YAAY,EAAEJ,QAAQ,EAAEI;EAC1B,CAAC,CAAC;AACJ;AAEO,SAASC,eAAeA,CAACT,GAAW,EAAEU,KAAa,EAAEC,MAAc,EAAE;EAC1E,MAAMP,QAAQ,GAAGP,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;EAClC,IAAII,QAAQ,EAAE;IACZA,QAAQ,CAACG,WAAW,GAAGG,KAAK;IAC5BN,QAAQ,CAACI,YAAY,GAAGG,MAAM;EAChC;AACF;AAEO,SAASC,cAAcA,CAACZ,GAAW,EAA2B;EACnE,OAAOH,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;AAC1B;AAEO,SAASa,gBAAgBA,CAACb,GAAW,EAAE;EAC5CH,QAAQ,CAACiB,MAAM,CAACd,GAAG,CAAC;AACtB","ignoreList":[]}
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { Pressable, View, findNodeHandle } from 'react-native';
|
|
5
5
|
import NativeMorphCardModule from './specs/NativeMorphCardModule';
|
|
6
6
|
import NativeSourceViewSpec from './specs/NativeMorphCardSource';
|
|
7
|
+
import { setSourceEntry, setSourceLayout, clearSourceEntry } from './MorphChildrenRegistry';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
const NativeSourceView = NativeSourceViewSpec ?? View;
|
|
9
10
|
export const MorphCardSource = ({
|
|
@@ -14,12 +15,23 @@ export const MorphCardSource = ({
|
|
|
14
15
|
height,
|
|
15
16
|
borderRadius,
|
|
16
17
|
backgroundColor,
|
|
17
|
-
|
|
18
|
+
resizeMode,
|
|
18
19
|
onPress,
|
|
19
20
|
ref
|
|
20
21
|
}) => {
|
|
21
22
|
const nativeRef = React.useRef(null);
|
|
22
23
|
React.useImperativeHandle(ref, () => nativeRef.current);
|
|
24
|
+
|
|
25
|
+
// Store children in shared registry so MorphCardTarget can clone them
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
const tag = findNodeHandle(nativeRef.current);
|
|
28
|
+
if (tag != null) {
|
|
29
|
+
setSourceEntry(tag, children, backgroundColor, resizeMode);
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
if (tag != null) clearSourceEntry(tag);
|
|
33
|
+
};
|
|
34
|
+
}, [children, backgroundColor, resizeMode]);
|
|
23
35
|
const style = {};
|
|
24
36
|
if (width != null) style.width = width;
|
|
25
37
|
if (height != null) style.height = height;
|
|
@@ -28,6 +40,16 @@ export const MorphCardSource = ({
|
|
|
28
40
|
style.overflow = 'hidden';
|
|
29
41
|
}
|
|
30
42
|
if (backgroundColor != null) style.backgroundColor = backgroundColor;
|
|
43
|
+
const handleLayout = React.useCallback(e => {
|
|
44
|
+
const tag = findNodeHandle(nativeRef.current);
|
|
45
|
+
if (tag != null) {
|
|
46
|
+
const {
|
|
47
|
+
width: lw,
|
|
48
|
+
height: lh
|
|
49
|
+
} = e.nativeEvent.layout;
|
|
50
|
+
setSourceLayout(tag, lw, lh);
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
31
53
|
const handlePress = React.useCallback(() => {
|
|
32
54
|
if (!onPress) return;
|
|
33
55
|
const tag = findNodeHandle(nativeRef.current);
|
|
@@ -43,9 +65,10 @@ export const MorphCardSource = ({
|
|
|
43
65
|
ref: nativeRef,
|
|
44
66
|
duration: duration,
|
|
45
67
|
expandDuration: expandDuration,
|
|
46
|
-
scaleMode:
|
|
68
|
+
scaleMode: resizeMode === 'contain' ? 'aspectFit' : resizeMode === 'stretch' ? 'stretch' : 'aspectFill',
|
|
47
69
|
cardBorderRadius: borderRadius,
|
|
48
70
|
style: style,
|
|
71
|
+
onLayout: handleLayout,
|
|
49
72
|
children: children
|
|
50
73
|
});
|
|
51
74
|
if (onPress) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Pressable","View","findNodeHandle","NativeMorphCardModule","NativeSourceViewSpec","jsx","_jsx","NativeSourceView","MorphCardSource","children","duration","expandDuration","width","height","borderRadius","backgroundColor","
|
|
1
|
+
{"version":3,"names":["React","Pressable","View","findNodeHandle","NativeMorphCardModule","NativeSourceViewSpec","setSourceEntry","setSourceLayout","clearSourceEntry","jsx","_jsx","NativeSourceView","MorphCardSource","children","duration","expandDuration","width","height","borderRadius","backgroundColor","resizeMode","onPress","ref","nativeRef","useRef","useImperativeHandle","current","useEffect","tag","style","overflow","handleLayout","useCallback","e","lw","lh","nativeEvent","layout","handlePress","prepareExpand","requestAnimationFrame","content","scaleMode","cardBorderRadius","onLayout","getViewTag","viewRef","morphExpand","sourceRef","targetRef","sourceTag","targetTag","expand","morphCollapse","collapse"],"sourceRoot":"../../src","sources":["MorphCardSource.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,SAAS,EAITC,IAAI,EACJC,cAAc,QACT,cAAc;AACrB,OAAOC,qBAAqB,MAAM,+BAA+B;AACjE,OAAOC,oBAAoB,MAAM,+BAA+B;AAChE,SAASC,cAAc,EAAEC,eAAe,EAAEC,gBAAgB,QAAQ,y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A;AACA;AACA;AACA,OAAO,SAASI,UAAUA,CAACC,OAA6B,EAAiB;EACvE,OAAO3C,cAAc,CAAC2C,OAAO,CAACpB,OAAO,CAAC;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeqB,WAAWA,CAC/BC,SAA+B,EAC/BC,SAA+B,EACb;EAClB,MAAMC,SAAS,GAAG/C,cAAc,CAAC6C,SAAS,CAACtB,OAAO,CAAC;EACnD,MAAMyB,SAAS,GAAGhD,cAAc,CAAC8C,SAAS,CAACvB,OAAO,CAAC;EACnD,IAAI,CAACwB,SAAS,IAAI,CAACC,SAAS,EAAE,OAAO,KAAK;EAC1C,OAAO/C,qBAAqB,CAACgD,MAAM,CAACF,SAAS,EAAEC,SAAS,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeE,aAAaA,CAACH,SAAiB,EAAoB;EACvE,OAAO9C,qBAAqB,CAACkD,QAAQ,CAACJ,SAAS,CAAC;AAClD","ignoreList":[]}
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { View, findNodeHandle } from 'react-native';
|
|
5
5
|
import NativeMorphCardModule from './specs/NativeMorphCardModule';
|
|
6
6
|
import NativeTargetViewSpec from './specs/NativeMorphCardTarget';
|
|
7
|
+
import { getSourceEntry } from './MorphChildrenRegistry';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
const NativeTargetView = NativeTargetViewSpec ?? View;
|
|
9
10
|
export const MorphCardTarget = ({
|
|
@@ -46,16 +47,32 @@ export const MorphCardTarget = ({
|
|
|
46
47
|
NativeMorphCardModule.setTargetConfig(sourceTag, lw, lh, borderRadius != null ? borderRadius : -1, contentOffsetY ?? 0, contentCentered ?? false);
|
|
47
48
|
NativeMorphCardModule.expand(sourceTag, targetTag);
|
|
48
49
|
}, [sourceTag, borderRadius, contentOffsetY, contentCentered]);
|
|
49
|
-
const
|
|
50
|
+
const sourceEntry = getSourceEntry(sourceTag);
|
|
51
|
+
const containerStyle = {
|
|
52
|
+
overflow: 'hidden'
|
|
53
|
+
};
|
|
54
|
+
if (sourceEntry?.backgroundColor) {
|
|
55
|
+
containerStyle.backgroundColor = sourceEntry.backgroundColor;
|
|
56
|
+
}
|
|
57
|
+
if (contentCentered) {
|
|
58
|
+
containerStyle.justifyContent = 'center';
|
|
59
|
+
containerStyle.alignItems = 'center';
|
|
60
|
+
}
|
|
61
|
+
if (contentOffsetY) {
|
|
62
|
+
containerStyle.paddingTop = contentOffsetY;
|
|
63
|
+
}
|
|
50
64
|
if (width != null) {
|
|
51
|
-
|
|
65
|
+
containerStyle.width = width;
|
|
52
66
|
} else if (sourceSize) {
|
|
53
|
-
|
|
67
|
+
containerStyle.width = sourceSize.width;
|
|
54
68
|
}
|
|
55
69
|
if (height != null) {
|
|
56
|
-
|
|
70
|
+
containerStyle.height = height;
|
|
57
71
|
} else if (sourceSize) {
|
|
58
|
-
|
|
72
|
+
containerStyle.height = sourceSize.height;
|
|
73
|
+
}
|
|
74
|
+
if (borderRadius) {
|
|
75
|
+
containerStyle.borderRadius = borderRadius;
|
|
59
76
|
}
|
|
60
77
|
return /*#__PURE__*/_jsx(NativeTargetView, {
|
|
61
78
|
ref: nativeRef,
|
|
@@ -64,8 +81,15 @@ export const MorphCardTarget = ({
|
|
|
64
81
|
targetWidth: 0,
|
|
65
82
|
targetHeight: 0,
|
|
66
83
|
targetBorderRadius: borderRadius != null ? borderRadius : -1,
|
|
67
|
-
style:
|
|
68
|
-
onLayout: handleLayout
|
|
84
|
+
style: containerStyle,
|
|
85
|
+
onLayout: handleLayout,
|
|
86
|
+
children: sourceEntry && !sourceEntry.scaleMode && (sourceEntry.backgroundColor && sourceEntry.layoutWidth ? /*#__PURE__*/_jsx(View, {
|
|
87
|
+
style: {
|
|
88
|
+
width: sourceEntry.layoutWidth,
|
|
89
|
+
height: sourceEntry.layoutHeight
|
|
90
|
+
},
|
|
91
|
+
children: sourceEntry.children
|
|
92
|
+
}) : sourceEntry.children)
|
|
69
93
|
});
|
|
70
94
|
};
|
|
71
95
|
//# sourceMappingURL=MorphCardTarget.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","View","findNodeHandle","NativeMorphCardModule","NativeTargetViewSpec","jsx","_jsx","NativeTargetView","MorphCardTarget","sourceTag","collapseDuration","width","height","borderRadius","contentOffsetY","contentCentered","nativeRef","useRef","expandedRef","sourceSize","setSourceSize","useState","useEffect","cancelled","getSourceSize","then","size","catch","handleLayout","useCallback","e","current","lw","lh","nativeEvent","layout","targetTag","setTargetConfig","expand","
|
|
1
|
+
{"version":3,"names":["React","View","findNodeHandle","NativeMorphCardModule","NativeTargetViewSpec","getSourceEntry","jsx","_jsx","NativeTargetView","MorphCardTarget","sourceTag","collapseDuration","width","height","borderRadius","contentOffsetY","contentCentered","nativeRef","useRef","expandedRef","sourceSize","setSourceSize","useState","useEffect","cancelled","getSourceSize","then","size","catch","handleLayout","useCallback","e","current","lw","lh","nativeEvent","layout","targetTag","setTargetConfig","expand","sourceEntry","containerStyle","overflow","backgroundColor","justifyContent","alignItems","paddingTop","ref","targetWidth","targetHeight","targetBorderRadius","style","onLayout","children","scaleMode","layoutWidth","layoutHeight"],"sourceRoot":"../../src","sources":["MorphCardTarget.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAGEC,IAAI,EACJC,cAAc,QAET,cAAc;AACrB,OAAOC,qBAAqB,MAAM,+BAA+B;AACjE,OAAOC,oBAAoB,MAAM,+BAA+B;AAChE,SAASC,cAAc,QAAQ,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEzD,MAAMC,gBAAgB,GAAGJ,oBAAoB,IAAIH,IAAI;AAmBrD,OAAO,MAAMQ,eAAe,GAAGA,CAAC;EAC9BC,SAAS;EACTC,gBAAgB;EAChBC,KAAK;EACLC,MAAM;EACNC,YAAY;EACZC,cAAc;EACdC;AACoB,CAAC,KAAK;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AAGA,YAAY,GAAG,CAAC,CAAE;IAC7DqC,KAAK,EAAEV,cAAe;IACtBW,QAAQ,EAAEvB,YAAa;IAAAwB,QAAA,EAEtBb,WAAW,IACV,CAACA,WAAW,CAACc,SAAS,KACrBd,WAAW,CAACG,eAAe,IAAIH,WAAW,CAACe,WAAW,gBACrDhD,IAAA,CAACN,IAAI;MACHkD,KAAK,EAAE;QACLvC,KAAK,EAAE4B,WAAW,CAACe,WAAW;QAC9B1C,MAAM,EAAE2B,WAAW,CAACgB;MACtB,CAAE;MAAAH,QAAA,EAEDb,WAAW,CAACa;IAAQ,CACjB,CAAC,GAEPb,WAAW,CAACa,QACb;EAAC,CACY,CAAC;AAEvB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const registry = new Map();
|
|
4
|
+
export function setSourceEntry(tag, children, backgroundColor, scaleMode) {
|
|
5
|
+
const existing = registry.get(tag);
|
|
6
|
+
registry.set(tag, {
|
|
7
|
+
children,
|
|
8
|
+
backgroundColor,
|
|
9
|
+
scaleMode,
|
|
10
|
+
layoutWidth: existing?.layoutWidth,
|
|
11
|
+
layoutHeight: existing?.layoutHeight
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function setSourceLayout(tag, width, height) {
|
|
15
|
+
const existing = registry.get(tag);
|
|
16
|
+
if (existing) {
|
|
17
|
+
existing.layoutWidth = width;
|
|
18
|
+
existing.layoutHeight = height;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function getSourceEntry(tag) {
|
|
22
|
+
return registry.get(tag);
|
|
23
|
+
}
|
|
24
|
+
export function clearSourceEntry(tag) {
|
|
25
|
+
registry.delete(tag);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=MorphChildrenRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","Map","setSourceEntry","tag","children","backgroundColor","scaleMode","existing","get","set","layoutWidth","layoutHeight","setSourceLayout","width","height","getSourceEntry","clearSourceEntry","delete"],"sourceRoot":"../../src","sources":["MorphChildrenRegistry.ts"],"mappings":";;AAUA,MAAMA,QAAQ,GAAG,IAAIC,GAAG,CAAsB,CAAC;AAE/C,OAAO,SAASC,cAAcA,CAC5BC,GAAW,EACXC,QAAmB,EACnBC,eAAwB,EACxBC,SAAkB,EAClB;EACA,MAAMC,QAAQ,GAAGP,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;EAClCH,QAAQ,CAACS,GAAG,CAACN,GAAG,EAAE;IAChBC,QAAQ;IACRC,eAAe;IACfC,SAAS;IACTI,WAAW,EAAEH,QAAQ,EAAEG,WAAW;IAClCC,YAAY,EAAEJ,QAAQ,EAAEI;EAC1B,CAAC,CAAC;AACJ;AAEA,OAAO,SAASC,eAAeA,CAACT,GAAW,EAAEU,KAAa,EAAEC,MAAc,EAAE;EAC1E,MAAMP,QAAQ,GAAGP,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;EAClC,IAAII,QAAQ,EAAE;IACZA,QAAQ,CAACG,WAAW,GAAGG,KAAK;IAC5BN,QAAQ,CAACI,YAAY,GAAGG,MAAM;EAChC;AACF;AAEA,OAAO,SAASC,cAAcA,CAACZ,GAAW,EAA2B;EACnE,OAAOH,QAAQ,CAACQ,GAAG,CAACL,GAAG,CAAC;AAC1B;AAEA,OAAO,SAASa,gBAAgBA,CAACb,GAAW,EAAE;EAC5CH,QAAQ,CAACiB,MAAM,CAACd,GAAG,CAAC;AACtB","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type DimensionValue } from 'react-native';
|
|
3
|
-
export type
|
|
3
|
+
export type ResizeMode = 'cover' | 'contain' | 'stretch';
|
|
4
4
|
export interface MorphCardSourceProps {
|
|
5
5
|
ref?: React.Ref<any>;
|
|
6
6
|
duration?: number;
|
|
@@ -9,12 +9,12 @@ export interface MorphCardSourceProps {
|
|
|
9
9
|
height?: DimensionValue;
|
|
10
10
|
borderRadius?: number;
|
|
11
11
|
backgroundColor?: string;
|
|
12
|
-
/** How the snapshot scales in no-wrapper mode (no backgroundColor). Default: '
|
|
13
|
-
|
|
12
|
+
/** How the snapshot scales in no-wrapper mode (no backgroundColor). Default: 'cover' */
|
|
13
|
+
resizeMode?: ResizeMode;
|
|
14
14
|
onPress?: (sourceTag: number) => void;
|
|
15
15
|
children: React.ReactNode;
|
|
16
16
|
}
|
|
17
|
-
export declare const MorphCardSource: ({ children, duration, expandDuration, width, height, borderRadius, backgroundColor,
|
|
17
|
+
export declare const MorphCardSource: ({ children, duration, expandDuration, width, height, borderRadius, backgroundColor, resizeMode, onPress, ref, }: MorphCardSourceProps) => React.JSX.Element;
|
|
18
18
|
/**
|
|
19
19
|
* Get the native view tag from a ref. Useful for passing sourceTag
|
|
20
20
|
* to the detail screen via navigation params.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MorphCardSource.d.ts","sourceRoot":"","sources":["../../../src/MorphCardSource.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"MorphCardSource.d.ts","sourceRoot":"","sources":["../../../src/MorphCardSource.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,KAAK,cAAc,EAIpB,MAAM,cAAc,CAAC;AAOtB,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,eAAO,MAAM,eAAe,GAAI,iHAW7B,oBAAoB,sBAuDtB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,CAEvE;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAC/B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAC9B,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MorphCardTarget.d.ts","sourceRoot":"","sources":["../../../src/MorphCardTarget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAEL,KAAK,cAAc,EAIpB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"MorphCardTarget.d.ts","sourceRoot":"","sources":["../../../src/MorphCardTarget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAEL,KAAK,cAAc,EAIpB,MAAM,cAAc,CAAC;AAOtB,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,sFAAsF;IACtF,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,2GAA2G;IAC3G,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gGAAgG;IAChG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,eAAe,GAAI,gGAQ7B,oBAAoB,sBA0GtB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface SourceEntry {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
backgroundColor?: string;
|
|
5
|
+
scaleMode?: string;
|
|
6
|
+
layoutWidth?: number;
|
|
7
|
+
layoutHeight?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function setSourceEntry(tag: number, children: ReactNode, backgroundColor?: string, scaleMode?: string): void;
|
|
10
|
+
export declare function setSourceLayout(tag: number, width: number, height: number): void;
|
|
11
|
+
export declare function getSourceEntry(tag: number): SourceEntry | undefined;
|
|
12
|
+
export declare function clearSourceEntry(tag: number): void;
|
|
13
|
+
//# sourceMappingURL=MorphChildrenRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphChildrenRegistry.d.ts","sourceRoot":"","sources":["../../../src/MorphChildrenRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,EACnB,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,CAAC,EAAE,MAAM,QAUnB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAMzE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEnE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,QAE3C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { MorphCardSource, morphExpand, morphCollapse, getViewTag, } from './MorphCardSource';
|
|
2
|
-
export type { MorphCardSourceProps,
|
|
2
|
+
export type { MorphCardSourceProps, ResizeMode } from './MorphCardSource';
|
|
3
3
|
export { MorphCardTarget } from './MorphCardTarget';
|
|
4
4
|
export type { MorphCardTargetProps } from './MorphCardTarget';
|
|
5
5
|
export { useMorphTarget } from './useMorphTarget';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EACX,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EACX,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
package/src/MorphCardSource.tsx
CHANGED
|
@@ -3,15 +3,17 @@ import {
|
|
|
3
3
|
Pressable,
|
|
4
4
|
type ViewStyle,
|
|
5
5
|
type DimensionValue,
|
|
6
|
+
type LayoutChangeEvent,
|
|
6
7
|
View,
|
|
7
8
|
findNodeHandle,
|
|
8
9
|
} from 'react-native';
|
|
9
10
|
import NativeMorphCardModule from './specs/NativeMorphCardModule';
|
|
10
11
|
import NativeSourceViewSpec from './specs/NativeMorphCardSource';
|
|
12
|
+
import { setSourceEntry, setSourceLayout, clearSourceEntry } from './MorphChildrenRegistry';
|
|
11
13
|
|
|
12
14
|
const NativeSourceView = NativeSourceViewSpec ?? View;
|
|
13
15
|
|
|
14
|
-
export type
|
|
16
|
+
export type ResizeMode = 'cover' | 'contain' | 'stretch';
|
|
15
17
|
|
|
16
18
|
export interface MorphCardSourceProps {
|
|
17
19
|
ref?: React.Ref<any>;
|
|
@@ -21,8 +23,8 @@ export interface MorphCardSourceProps {
|
|
|
21
23
|
height?: DimensionValue;
|
|
22
24
|
borderRadius?: number;
|
|
23
25
|
backgroundColor?: string;
|
|
24
|
-
/** How the snapshot scales in no-wrapper mode (no backgroundColor). Default: '
|
|
25
|
-
|
|
26
|
+
/** How the snapshot scales in no-wrapper mode (no backgroundColor). Default: 'cover' */
|
|
27
|
+
resizeMode?: ResizeMode;
|
|
26
28
|
onPress?: (sourceTag: number) => void;
|
|
27
29
|
children: React.ReactNode;
|
|
28
30
|
}
|
|
@@ -35,13 +37,24 @@ export const MorphCardSource = ({
|
|
|
35
37
|
height,
|
|
36
38
|
borderRadius,
|
|
37
39
|
backgroundColor,
|
|
38
|
-
|
|
40
|
+
resizeMode,
|
|
39
41
|
onPress,
|
|
40
42
|
ref,
|
|
41
43
|
}: MorphCardSourceProps) => {
|
|
42
44
|
const nativeRef = React.useRef<any>(null);
|
|
43
45
|
React.useImperativeHandle(ref, () => nativeRef.current);
|
|
44
46
|
|
|
47
|
+
// Store children in shared registry so MorphCardTarget can clone them
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
const tag = findNodeHandle(nativeRef.current);
|
|
50
|
+
if (tag != null) {
|
|
51
|
+
setSourceEntry(tag, children, backgroundColor, resizeMode);
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
if (tag != null) clearSourceEntry(tag);
|
|
55
|
+
};
|
|
56
|
+
}, [children, backgroundColor, resizeMode]);
|
|
57
|
+
|
|
45
58
|
const style: ViewStyle = {};
|
|
46
59
|
if (width != null) style.width = width as ViewStyle['width'];
|
|
47
60
|
if (height != null) style.height = height as ViewStyle['height'];
|
|
@@ -50,6 +63,15 @@ export const MorphCardSource = ({
|
|
|
50
63
|
style.overflow = 'hidden';
|
|
51
64
|
}
|
|
52
65
|
if (backgroundColor != null) style.backgroundColor = backgroundColor;
|
|
66
|
+
|
|
67
|
+
const handleLayout = React.useCallback((e: LayoutChangeEvent) => {
|
|
68
|
+
const tag = findNodeHandle(nativeRef.current);
|
|
69
|
+
if (tag != null) {
|
|
70
|
+
const { width: lw, height: lh } = e.nativeEvent.layout;
|
|
71
|
+
setSourceLayout(tag, lw, lh);
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
53
75
|
const handlePress = React.useCallback(() => {
|
|
54
76
|
if (!onPress) return;
|
|
55
77
|
const tag = findNodeHandle(nativeRef.current);
|
|
@@ -63,7 +85,7 @@ export const MorphCardSource = ({
|
|
|
63
85
|
}, [onPress]);
|
|
64
86
|
|
|
65
87
|
const content = (
|
|
66
|
-
<NativeSourceView ref={nativeRef} duration={duration} expandDuration={expandDuration} scaleMode={
|
|
88
|
+
<NativeSourceView ref={nativeRef} duration={duration} expandDuration={expandDuration} scaleMode={resizeMode === 'contain' ? 'aspectFit' : resizeMode === 'stretch' ? 'stretch' : 'aspectFill'} cardBorderRadius={borderRadius} style={style} onLayout={handleLayout}>
|
|
67
89
|
{children}
|
|
68
90
|
</NativeSourceView>
|
|
69
91
|
);
|
package/src/MorphCardTarget.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from 'react-native';
|
|
9
9
|
import NativeMorphCardModule from './specs/NativeMorphCardModule';
|
|
10
10
|
import NativeTargetViewSpec from './specs/NativeMorphCardTarget';
|
|
11
|
+
import { getSourceEntry } from './MorphChildrenRegistry';
|
|
11
12
|
|
|
12
13
|
const NativeTargetView = NativeTargetViewSpec ?? View;
|
|
13
14
|
|
|
@@ -77,23 +78,42 @@ export const MorphCardTarget = ({
|
|
|
77
78
|
lh,
|
|
78
79
|
borderRadius != null ? borderRadius : -1,
|
|
79
80
|
contentOffsetY ?? 0,
|
|
80
|
-
contentCentered ?? false
|
|
81
|
+
contentCentered ?? false,
|
|
81
82
|
);
|
|
82
83
|
NativeMorphCardModule.expand(sourceTag, targetTag);
|
|
83
84
|
},
|
|
84
|
-
[sourceTag, borderRadius, contentOffsetY, contentCentered]
|
|
85
|
+
[sourceTag, borderRadius, contentOffsetY, contentCentered],
|
|
85
86
|
);
|
|
86
87
|
|
|
87
|
-
const
|
|
88
|
+
const sourceEntry = getSourceEntry(sourceTag);
|
|
89
|
+
|
|
90
|
+
const containerStyle: ViewStyle = {
|
|
91
|
+
overflow: 'hidden',
|
|
92
|
+
};
|
|
93
|
+
if (sourceEntry?.backgroundColor) {
|
|
94
|
+
containerStyle.backgroundColor = sourceEntry.backgroundColor;
|
|
95
|
+
}
|
|
96
|
+
if (contentCentered) {
|
|
97
|
+
containerStyle.justifyContent = 'center';
|
|
98
|
+
containerStyle.alignItems = 'center';
|
|
99
|
+
}
|
|
100
|
+
if (contentOffsetY) {
|
|
101
|
+
containerStyle.paddingTop = contentOffsetY;
|
|
102
|
+
}
|
|
103
|
+
|
|
88
104
|
if (width != null) {
|
|
89
|
-
|
|
105
|
+
containerStyle.width = width;
|
|
90
106
|
} else if (sourceSize) {
|
|
91
|
-
|
|
107
|
+
containerStyle.width = sourceSize.width;
|
|
92
108
|
}
|
|
93
109
|
if (height != null) {
|
|
94
|
-
|
|
110
|
+
containerStyle.height = height;
|
|
95
111
|
} else if (sourceSize) {
|
|
96
|
-
|
|
112
|
+
containerStyle.height = sourceSize.height;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (borderRadius) {
|
|
116
|
+
containerStyle.borderRadius = borderRadius;
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
return (
|
|
@@ -104,8 +124,23 @@ export const MorphCardTarget = ({
|
|
|
104
124
|
targetWidth={0}
|
|
105
125
|
targetHeight={0}
|
|
106
126
|
targetBorderRadius={borderRadius != null ? borderRadius : -1}
|
|
107
|
-
style={
|
|
127
|
+
style={containerStyle}
|
|
108
128
|
onLayout={handleLayout}
|
|
109
|
-
|
|
129
|
+
>
|
|
130
|
+
{sourceEntry &&
|
|
131
|
+
!sourceEntry.scaleMode &&
|
|
132
|
+
(sourceEntry.backgroundColor && sourceEntry.layoutWidth ? (
|
|
133
|
+
<View
|
|
134
|
+
style={{
|
|
135
|
+
width: sourceEntry.layoutWidth,
|
|
136
|
+
height: sourceEntry.layoutHeight,
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
{sourceEntry.children}
|
|
140
|
+
</View>
|
|
141
|
+
) : (
|
|
142
|
+
sourceEntry.children
|
|
143
|
+
))}
|
|
144
|
+
</NativeTargetView>
|
|
110
145
|
);
|
|
111
146
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface SourceEntry {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
scaleMode?: string;
|
|
7
|
+
layoutWidth?: number;
|
|
8
|
+
layoutHeight?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const registry = new Map<number, SourceEntry>();
|
|
12
|
+
|
|
13
|
+
export function setSourceEntry(
|
|
14
|
+
tag: number,
|
|
15
|
+
children: ReactNode,
|
|
16
|
+
backgroundColor?: string,
|
|
17
|
+
scaleMode?: string
|
|
18
|
+
) {
|
|
19
|
+
const existing = registry.get(tag);
|
|
20
|
+
registry.set(tag, {
|
|
21
|
+
children,
|
|
22
|
+
backgroundColor,
|
|
23
|
+
scaleMode,
|
|
24
|
+
layoutWidth: existing?.layoutWidth,
|
|
25
|
+
layoutHeight: existing?.layoutHeight,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function setSourceLayout(tag: number, width: number, height: number) {
|
|
30
|
+
const existing = registry.get(tag);
|
|
31
|
+
if (existing) {
|
|
32
|
+
existing.layoutWidth = width;
|
|
33
|
+
existing.layoutHeight = height;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getSourceEntry(tag: number): SourceEntry | undefined {
|
|
38
|
+
return registry.get(tag);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function clearSourceEntry(tag: number) {
|
|
42
|
+
registry.delete(tag);
|
|
43
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -4,7 +4,7 @@ export {
|
|
|
4
4
|
morphCollapse,
|
|
5
5
|
getViewTag,
|
|
6
6
|
} from './MorphCardSource';
|
|
7
|
-
export type { MorphCardSourceProps,
|
|
7
|
+
export type { MorphCardSourceProps, ResizeMode } from './MorphCardSource';
|
|
8
8
|
export { MorphCardTarget } from './MorphCardTarget';
|
|
9
9
|
export type { MorphCardTargetProps } from './MorphCardTarget';
|
|
10
10
|
export { useMorphTarget } from './useMorphTarget';
|