one
Version:
One is a React framework for web, iOS, and Android apps.
66 lines (63 loc) • 2.64 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 Image_native_exports = {};
__export(Image_native_exports, { Image: () => Image });
module.exports = __toCommonJS(Image_native_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_NativeNitroImage = require("react-native-nitro-image/src/NativeNitroImage");
var import_loadImage = require("react-native-nitro-image/src/loadImage");
function Image(param) {
var { source, resizeMode = "cover", onLoadStart, onLoad, onError, onLoadEnd, ...props } = param;
var uri = typeof source === "number" ? source : typeof source === "string" ? source : source.uri;
var [loaded, setLoaded] = (0, import_react.useState)();
(0, import_react.useEffect)(function() {
var cancelled = false;
onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart();
Promise.resolve((0, import_loadImage.loadImage)(typeof uri === "number" ? uri : { url: uri })).then(function(image) {
if (cancelled) return;
setLoaded({
uri,
image
});
onLoad === null || onLoad === void 0 ? void 0 : onLoad({ nativeEvent: { source: {
uri: String(uri),
width: image.width,
height: image.height
} } });
onLoadEnd === null || onLoadEnd === void 0 ? void 0 : onLoadEnd();
}, function(error) {
if (cancelled) return;
onError === null || onError === void 0 ? void 0 : onError({ nativeEvent: { error: error instanceof Error ? error.message : String(error) } });
onLoadEnd === null || onLoadEnd === void 0 ? void 0 : onLoadEnd();
});
return function() {
cancelled = true;
};
}, [uri]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_NativeNitroImage.NativeNitroImage, {
image: (loaded === null || loaded === void 0 ? void 0 : loaded.uri) === uri ? loaded.image : void 0,
resizeMode,
...props
}, String(uri));
}
//# sourceMappingURL=Image.native.js.map