one
Version:
One is a React framework for web, iOS, and Android apps.
44 lines (41 loc) • 1.87 kB
JavaScript
import { sdkAnimationValues } from "./generated/controlTypes.native.js";
import { getNativeSyncFactory } from "./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 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 ${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");
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);
}
}
export { withAnimation };
//# sourceMappingURL=withAnimation.native.js.map