@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.js
CHANGED
|
@@ -116,6 +116,8 @@ var buyButtonSpec = {
|
|
|
116
116
|
},
|
|
117
117
|
mapMessage: (msg) => {
|
|
118
118
|
switch (msg.kind) {
|
|
119
|
+
case "ready":
|
|
120
|
+
return { kind: "ready" };
|
|
119
121
|
case "complete":
|
|
120
122
|
return { kind: "complete", payload: msg.payload };
|
|
121
123
|
case "challenge":
|
|
@@ -893,7 +895,34 @@ import {
|
|
|
893
895
|
useWindowDimensions,
|
|
894
896
|
View as View2
|
|
895
897
|
} from "react-native";
|
|
898
|
+
|
|
899
|
+
// src/sheet-presentation.ts
|
|
900
|
+
var NOOP = {
|
|
901
|
+
present: false,
|
|
902
|
+
liftSpinner: false,
|
|
903
|
+
dismissSilent: false,
|
|
904
|
+
close: false
|
|
905
|
+
};
|
|
906
|
+
function resolvePresentation(phase, signal) {
|
|
907
|
+
if (phase === "closed")
|
|
908
|
+
return { phase: "closed", ...NOOP };
|
|
909
|
+
switch (signal) {
|
|
910
|
+
case "ready":
|
|
911
|
+
return { ...NOOP, phase: "presented", present: phase === "hidden", liftSpinner: true };
|
|
912
|
+
case "grace":
|
|
913
|
+
if (phase === "presented")
|
|
914
|
+
return { phase: "presented", ...NOOP };
|
|
915
|
+
return { ...NOOP, phase: "presented", present: true };
|
|
916
|
+
case "terminal":
|
|
917
|
+
if (phase === "hidden")
|
|
918
|
+
return { ...NOOP, phase: "closed", dismissSilent: true };
|
|
919
|
+
return { ...NOOP, phase: "closed", close: true };
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// src/VisibleFrameSlotSheet.tsx
|
|
896
924
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
925
|
+
var PRESENT_GRACE_MS = 3e3;
|
|
897
926
|
function animateSheet(value, toValue, onDone) {
|
|
898
927
|
const animation = Platform.OS === "android" ? Animated.timing(value, {
|
|
899
928
|
toValue,
|
|
@@ -920,6 +949,8 @@ function VisibleFrameSlotSheet({
|
|
|
920
949
|
const sheetHeight = Math.round(height * 0.9);
|
|
921
950
|
const translateY = useRef2(new Animated.Value(sheetHeight)).current;
|
|
922
951
|
const [frameReady, setFrameReady] = useState(false);
|
|
952
|
+
const [presented, setPresented] = useState(false);
|
|
953
|
+
const phaseRef = useRef2("hidden");
|
|
923
954
|
const onCloseRef = useRef2(onClose);
|
|
924
955
|
onCloseRef.current = onClose;
|
|
925
956
|
const closingRef = useRef2(false);
|
|
@@ -927,6 +958,7 @@ function VisibleFrameSlotSheet({
|
|
|
927
958
|
if (closingRef.current)
|
|
928
959
|
return;
|
|
929
960
|
closingRef.current = true;
|
|
961
|
+
phaseRef.current = "closed";
|
|
930
962
|
animateSheet(translateY, sheetHeight, ({ finished }) => {
|
|
931
963
|
if (finished)
|
|
932
964
|
onCloseRef.current();
|
|
@@ -964,24 +996,42 @@ function VisibleFrameSlotSheet({
|
|
|
964
996
|
}),
|
|
965
997
|
[translateY, sheetHeight, close]
|
|
966
998
|
);
|
|
999
|
+
const dispatch = useCallback(
|
|
1000
|
+
(signal) => {
|
|
1001
|
+
const result = resolvePresentation(phaseRef.current, signal);
|
|
1002
|
+
phaseRef.current = result.phase;
|
|
1003
|
+
if (result.present) {
|
|
1004
|
+
setPresented(true);
|
|
1005
|
+
animateSheet(translateY, 0);
|
|
1006
|
+
}
|
|
1007
|
+
if (result.liftSpinner)
|
|
1008
|
+
setFrameReady(true);
|
|
1009
|
+
if (result.dismissSilent)
|
|
1010
|
+
onCloseRef.current();
|
|
1011
|
+
if (result.close)
|
|
1012
|
+
close();
|
|
1013
|
+
},
|
|
1014
|
+
[translateY, close]
|
|
1015
|
+
);
|
|
967
1016
|
useEffect2(() => {
|
|
968
|
-
|
|
969
|
-
|
|
1017
|
+
const timer = setTimeout(() => dispatch("grace"), PRESENT_GRACE_MS);
|
|
1018
|
+
return () => clearTimeout(timer);
|
|
1019
|
+
}, [dispatch]);
|
|
970
1020
|
useEffect2(() => {
|
|
971
1021
|
const unsubscribe = slot.transport.onMessage((msg) => {
|
|
972
1022
|
if (msg.kind === "ready")
|
|
973
|
-
|
|
1023
|
+
dispatch("ready");
|
|
974
1024
|
else if (msg.kind === "complete" || msg.kind === "error")
|
|
975
|
-
|
|
1025
|
+
dispatch("terminal");
|
|
976
1026
|
});
|
|
977
1027
|
return unsubscribe;
|
|
978
|
-
}, [slot.transport,
|
|
1028
|
+
}, [slot.transport, dispatch]);
|
|
979
1029
|
const backdropOpacity = translateY.interpolate({
|
|
980
1030
|
inputRange: [0, sheetHeight],
|
|
981
1031
|
outputRange: [1, 0],
|
|
982
1032
|
extrapolate: "clamp"
|
|
983
1033
|
});
|
|
984
|
-
return /* @__PURE__ */ jsx2(Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ jsxs(View2, { style: styles.root, children: [
|
|
1034
|
+
return /* @__PURE__ */ jsx2(Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ jsxs(View2, { style: styles.root, pointerEvents: presented ? "auto" : "none", children: [
|
|
985
1035
|
/* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], children: /* @__PURE__ */ jsx2(
|
|
986
1036
|
Pressable,
|
|
987
1037
|
{
|