one
Version:
One is a React framework for web, iOS, and Android apps.
43 lines (40 loc) • 1.61 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import { NativeNitroImage } from "react-native-nitro-image/src/NativeNitroImage";
import { loadImage } from "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] = useState();
useEffect(function() {
var cancelled = false;
onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart();
Promise.resolve(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__ */ jsx(NativeNitroImage, {
image: (loaded === null || loaded === void 0 ? void 0 : loaded.uri) === uri ? loaded.image : void 0,
resizeMode,
...props
}, String(uri));
}
export { Image };
//# sourceMappingURL=Image.native.js.map