one
Version:
One is a React framework for web, iOS, and Android apps.
67 lines (64 loc) • 2.87 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var withAnimation_native_exports = {};
__export(withAnimation_native_exports, { withAnimation: () => withAnimation });
module.exports = __toCommonJS(withAnimation_native_exports);
var import_controlTypes = require("./generated/controlTypes.native.js");
var import_syncNative = require("./syncNative.native.js");
function isNativeAnimation(value) {
return typeof value === "object" && value !== null && typeof Reflect.get(value, "begin") === "function" && typeof Reflect.get(value, "commit") === "function";
}
function isSDKAnimation(value) {
return import_controlTypes.sdkAnimationValues.some(function(name) {
return name === value;
});
}
var animating = false;
function withAnimation(animation, body, completion) {
var completionCriteria = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "logicallyComplete";
if (animation !== null && !isSDKAnimation(animation)) {
throw new Error(`Swift.withAnimation animation must be null or one of ${import_controlTypes.sdkAnimationValues.join(", ")}`);
}
if (typeof body !== "function") throw new Error("Swift.withAnimation body must be a function");
if (completion !== void 0 && typeof completion !== "function") {
throw new Error("Swift.withAnimation completion must be a function");
}
if (completionCriteria !== "logicallyComplete" && completionCriteria !== "removed") {
throw new Error("Swift.withAnimation completionCriteria must be logicallyComplete or removed");
}
if (animating) throw new Error("Swift.withAnimation cannot be called inside another withAnimation body");
(0, import_syncNative.getNativeSyncFactory)();
var native = Reflect.get(globalThis, "__OneNativeAnimation");
if (!isNativeAnimation(native)) throw new Error("Swift.withAnimation requires the OneNative iOS module");
animating = true;
native.begin();
var completed = false;
try {
body();
completed = true;
} finally {
animating = false;
if (completed) native.commit(animation, completionCriteria, completion);
else native.commit(null, completionCriteria);
}
}
//# sourceMappingURL=withAnimation.native.js.map