react-native-morph-card 0.2.7 → 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 +40 -31
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardSourceView.kt +27 -72
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardTargetManager.kt +2 -2
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardTargetView.kt +34 -39
- package/android/src/main/java/com/melivalesca/morphcard/MorphCardUtils.kt +43 -0
- package/ios/Fabric/RNCMorphCardSourceComponentView.h +0 -3
- package/ios/Fabric/RNCMorphCardSourceComponentView.mm +110 -80
- package/ios/Fabric/RNCMorphCardTargetComponentView.h +1 -0
- package/ios/Fabric/RNCMorphCardTargetComponentView.mm +26 -14
- package/ios/RNCMorphCardSource.m +1 -1
- 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
|
@@ -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,OAA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,CACO,CACnB;EAED,IAAIQ,OAAO,EAAE;IACX,oBAAOX,IAAA,CAACT,SAAS;MAACoB,OAAO,EAAEiB,WAAY;MAAAzB,QAAA,EAAE4B;IAAO,CAAY,CAAC;EAC/D;EAEA,OAAOA,OAAO;AAChB,CAAC;;AAED;AACA;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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AAgB;IACfuC,GAAG,EAAE9B,SAAU;IACfP,SAAS,EAAEA,SAAU;IACrBC,gBAAgB,EAAEA,gBAAiB;IACnCqC,WAAW,EAAE,CAAE;IACfC,YAAY,EAAE,CAAE;IAChBC,kBAAkB,EAAEpC,YAAY,IAAI,IAAI,GAAGA,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';
|