@moonpay/platform-sdk-react-native 1.2.0 → 1.4.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/dist/index.cjs +56 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -158,6 +158,8 @@ var buyButtonSpec = {
|
|
|
158
158
|
},
|
|
159
159
|
mapMessage: (msg) => {
|
|
160
160
|
switch (msg.kind) {
|
|
161
|
+
case "ready":
|
|
162
|
+
return { kind: "ready" };
|
|
161
163
|
case "complete":
|
|
162
164
|
return { kind: "complete", payload: msg.payload };
|
|
163
165
|
case "challenge":
|
|
@@ -912,7 +914,34 @@ function createMountSession(specCtx, host) {
|
|
|
912
914
|
// src/VisibleFrameSlotSheet.tsx
|
|
913
915
|
var import_react2 = require("react");
|
|
914
916
|
var import_react_native2 = require("react-native");
|
|
917
|
+
|
|
918
|
+
// src/sheet-presentation.ts
|
|
919
|
+
var NOOP = {
|
|
920
|
+
present: false,
|
|
921
|
+
liftSpinner: false,
|
|
922
|
+
dismissSilent: false,
|
|
923
|
+
close: false
|
|
924
|
+
};
|
|
925
|
+
function resolvePresentation(phase, signal) {
|
|
926
|
+
if (phase === "closed")
|
|
927
|
+
return { phase: "closed", ...NOOP };
|
|
928
|
+
switch (signal) {
|
|
929
|
+
case "ready":
|
|
930
|
+
return { ...NOOP, phase: "presented", present: phase === "hidden", liftSpinner: true };
|
|
931
|
+
case "grace":
|
|
932
|
+
if (phase === "presented")
|
|
933
|
+
return { phase: "presented", ...NOOP };
|
|
934
|
+
return { ...NOOP, phase: "presented", present: true };
|
|
935
|
+
case "terminal":
|
|
936
|
+
if (phase === "hidden")
|
|
937
|
+
return { ...NOOP, phase: "closed", dismissSilent: true };
|
|
938
|
+
return { ...NOOP, phase: "closed", close: true };
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/VisibleFrameSlotSheet.tsx
|
|
915
943
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
944
|
+
var PRESENT_GRACE_MS = 3e3;
|
|
916
945
|
function animateSheet(value, toValue, onDone) {
|
|
917
946
|
const animation = import_react_native2.Platform.OS === "android" ? import_react_native2.Animated.timing(value, {
|
|
918
947
|
toValue,
|
|
@@ -939,6 +968,8 @@ function VisibleFrameSlotSheet({
|
|
|
939
968
|
const sheetHeight = Math.round(height * 0.9);
|
|
940
969
|
const translateY = (0, import_react2.useRef)(new import_react_native2.Animated.Value(sheetHeight)).current;
|
|
941
970
|
const [frameReady, setFrameReady] = (0, import_react2.useState)(false);
|
|
971
|
+
const [presented, setPresented] = (0, import_react2.useState)(false);
|
|
972
|
+
const phaseRef = (0, import_react2.useRef)("hidden");
|
|
942
973
|
const onCloseRef = (0, import_react2.useRef)(onClose);
|
|
943
974
|
onCloseRef.current = onClose;
|
|
944
975
|
const closingRef = (0, import_react2.useRef)(false);
|
|
@@ -946,6 +977,7 @@ function VisibleFrameSlotSheet({
|
|
|
946
977
|
if (closingRef.current)
|
|
947
978
|
return;
|
|
948
979
|
closingRef.current = true;
|
|
980
|
+
phaseRef.current = "closed";
|
|
949
981
|
animateSheet(translateY, sheetHeight, ({ finished }) => {
|
|
950
982
|
if (finished)
|
|
951
983
|
onCloseRef.current();
|
|
@@ -983,24 +1015,42 @@ function VisibleFrameSlotSheet({
|
|
|
983
1015
|
}),
|
|
984
1016
|
[translateY, sheetHeight, close]
|
|
985
1017
|
);
|
|
1018
|
+
const dispatch = (0, import_react2.useCallback)(
|
|
1019
|
+
(signal) => {
|
|
1020
|
+
const result = resolvePresentation(phaseRef.current, signal);
|
|
1021
|
+
phaseRef.current = result.phase;
|
|
1022
|
+
if (result.present) {
|
|
1023
|
+
setPresented(true);
|
|
1024
|
+
animateSheet(translateY, 0);
|
|
1025
|
+
}
|
|
1026
|
+
if (result.liftSpinner)
|
|
1027
|
+
setFrameReady(true);
|
|
1028
|
+
if (result.dismissSilent)
|
|
1029
|
+
onCloseRef.current();
|
|
1030
|
+
if (result.close)
|
|
1031
|
+
close();
|
|
1032
|
+
},
|
|
1033
|
+
[translateY, close]
|
|
1034
|
+
);
|
|
986
1035
|
(0, import_react2.useEffect)(() => {
|
|
987
|
-
|
|
988
|
-
|
|
1036
|
+
const timer = setTimeout(() => dispatch("grace"), PRESENT_GRACE_MS);
|
|
1037
|
+
return () => clearTimeout(timer);
|
|
1038
|
+
}, [dispatch]);
|
|
989
1039
|
(0, import_react2.useEffect)(() => {
|
|
990
1040
|
const unsubscribe = slot.transport.onMessage((msg) => {
|
|
991
1041
|
if (msg.kind === "ready")
|
|
992
|
-
|
|
1042
|
+
dispatch("ready");
|
|
993
1043
|
else if (msg.kind === "complete" || msg.kind === "error")
|
|
994
|
-
|
|
1044
|
+
dispatch("terminal");
|
|
995
1045
|
});
|
|
996
1046
|
return unsubscribe;
|
|
997
|
-
}, [slot.transport,
|
|
1047
|
+
}, [slot.transport, dispatch]);
|
|
998
1048
|
const backdropOpacity = translateY.interpolate({
|
|
999
1049
|
inputRange: [0, sheetHeight],
|
|
1000
1050
|
outputRange: [1, 0],
|
|
1001
1051
|
extrapolate: "clamp"
|
|
1002
1052
|
});
|
|
1003
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.root, children: [
|
|
1053
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.root, pointerEvents: presented ? "auto" : "none", children: [
|
|
1004
1054
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1005
1055
|
import_react_native2.Pressable,
|
|
1006
1056
|
{
|