@granite-js/image 0.1.34 → 1.0.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/CHANGELOG.md +3 -277
- package/GraniteImage.podspec +72 -0
- package/android/build.gradle +178 -0
- package/android/gradle.properties +5 -0
- package/android/src/coil/java/run/granite/image/providers/CoilImageProvider.kt +156 -0
- package/android/src/glide/java/run/granite/image/providers/GlideImageProvider.kt +168 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/run/granite/image/GraniteImage.kt +277 -0
- package/android/src/main/java/run/granite/image/GraniteImageEvents.kt +83 -0
- package/android/src/main/java/run/granite/image/GraniteImageManager.kt +100 -0
- package/android/src/main/java/run/granite/image/GraniteImageModule.kt +131 -0
- package/android/src/main/java/run/granite/image/GraniteImagePackage.kt +59 -0
- package/android/src/main/java/run/granite/image/GraniteImageProvider.kt +105 -0
- package/android/src/main/java/run/granite/image/GraniteImageRegistry.kt +29 -0
- package/android/src/okhttp/java/run/granite/image/providers/OkHttpImageProvider.kt +228 -0
- package/dist/module/GraniteImage.js +127 -0
- package/dist/module/GraniteImage.js.map +1 -0
- package/dist/module/GraniteImageNativeComponent.ts +56 -0
- package/dist/module/NativeGraniteImageModule.js +5 -0
- package/dist/module/NativeGraniteImageModule.js.map +1 -0
- package/dist/module/index.js +6 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/typescript/GraniteImage.d.ts +35 -0
- package/dist/typescript/GraniteImageNativeComponent.d.ts +37 -0
- package/dist/typescript/NativeGraniteImageModule.d.ts +16 -0
- package/dist/typescript/index.d.ts +4 -0
- package/example/react-native.config.js +21 -0
- package/ios/GraniteImageComponentView.h +14 -0
- package/ios/GraniteImageComponentView.mm +388 -0
- package/ios/GraniteImageModule.swift +107 -0
- package/ios/GraniteImageModuleBridge.m +15 -0
- package/ios/GraniteImageProvider.swift +70 -0
- package/ios/GraniteImageRegistry.swift +30 -0
- package/ios/Providers/SDWebImageProvider.swift +175 -0
- package/package.json +71 -32
- package/src/GraniteImage.tsx +215 -0
- package/src/GraniteImageNativeComponent.ts +56 -0
- package/src/NativeGraniteImageModule.ts +16 -0
- package/src/index.ts +21 -0
- package/dist/index.d.mts +0 -70
- package/dist/index.d.ts +0 -70
- package/dist/index.js +0 -204
- package/dist/index.mjs +0 -180
package/dist/index.mjs
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import FastImage from "@granite-js/native/react-native-fast-image";
|
|
2
|
-
import { StyleSheet, View } from "react-native";
|
|
3
|
-
import { SvgUri, SvgXml } from "@granite-js/native/react-native-svg";
|
|
4
|
-
import { createElement, useCallback, useEffect, useState } from "react";
|
|
5
|
-
import { usePreservedCallback } from "react-simplikit";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
//#region src/SvgImage.tsx
|
|
9
|
-
/**
|
|
10
|
-
* @name SvgImage
|
|
11
|
-
* @category Components
|
|
12
|
-
* @description The `SvgImage` component loads and renders SVG images from a given external URL.
|
|
13
|
-
* @link https://github.com/software-mansion/react-native-svg/tree/v13.14.0/README.md
|
|
14
|
-
*
|
|
15
|
-
* @param {object} props - The `props` object passed to the component.
|
|
16
|
-
* @param {string} props.url - The URI address of the SVG image to load.
|
|
17
|
-
* @param {number | string} [props.width = '100%'] - Sets the horizontal size of the SVG image. Default value is '`100%`'.
|
|
18
|
-
* @param {number | string} [props.height = '100%'] - Sets the vertical size of the SVG image. Default value is '`100%`'.
|
|
19
|
-
* @param {object} props.style - Sets the style of the image component.
|
|
20
|
-
* @param {() => void} props.onLoadStart - A callback function called when the SVG image resource starts loading.
|
|
21
|
-
* @param {() => void} props.onLoadEnd - A callback function called after the SVG image resource is loaded.
|
|
22
|
-
* @param {() => void} props.onError - A callback function called when an error occurs during SVG image loading.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* import { SvgImage } from './SvgImage';
|
|
27
|
-
* import { View } from 'react-native';
|
|
28
|
-
*
|
|
29
|
-
* function MyComponent() {
|
|
30
|
-
* return (
|
|
31
|
-
* <View>
|
|
32
|
-
* <SvgImage
|
|
33
|
-
* url="https://example.com/icon.svg"
|
|
34
|
-
* width={100}
|
|
35
|
-
* height={100}
|
|
36
|
-
* onError={() => console.log('An error occurred while loading the SVG')}
|
|
37
|
-
* />
|
|
38
|
-
* </View>
|
|
39
|
-
* );
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
function SvgImage({ url, width = "100%", height = "100%", style, testID, onLoadStart: _onLoadStart, onLoadEnd: _onLoadEnd, onError: _onError }) {
|
|
44
|
-
const svgStyle = {
|
|
45
|
-
width,
|
|
46
|
-
height
|
|
47
|
-
};
|
|
48
|
-
const [data, setData] = useState(void 0);
|
|
49
|
-
const [isError, setIsError] = useState(false);
|
|
50
|
-
const onLoadStart = usePreservedCallback(() => _onLoadStart?.());
|
|
51
|
-
const onLoadEnd = usePreservedCallback(() => _onLoadEnd?.());
|
|
52
|
-
const onError = usePreservedCallback(() => _onError?.());
|
|
53
|
-
const Fallback = useCallback(() => createElement(View, { style: {
|
|
54
|
-
width,
|
|
55
|
-
height
|
|
56
|
-
} }, null), [width, height]);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
let isMounted = true;
|
|
59
|
-
/**
|
|
60
|
-
* First attempts to fetch the XML resource, and if that fails, tries to load directly by passing the URI to the Svg component
|
|
61
|
-
*/
|
|
62
|
-
async function fetchSvg() {
|
|
63
|
-
onLoadStart();
|
|
64
|
-
try {
|
|
65
|
-
const svg = await (await fetch(url)).text();
|
|
66
|
-
if (isMounted) {
|
|
67
|
-
onLoadEnd();
|
|
68
|
-
setData(svg);
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
setIsError(true);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
fetchSvg();
|
|
75
|
-
return () => {
|
|
76
|
-
isMounted = false;
|
|
77
|
-
};
|
|
78
|
-
}, [
|
|
79
|
-
onLoadStart,
|
|
80
|
-
onLoadEnd,
|
|
81
|
-
url
|
|
82
|
-
]);
|
|
83
|
-
if (data == null) return /* @__PURE__ */ jsx(Fallback, {});
|
|
84
|
-
if (isError) return /* @__PURE__ */ jsx(SvgUri, {
|
|
85
|
-
testID,
|
|
86
|
-
uri: url,
|
|
87
|
-
style,
|
|
88
|
-
...svgStyle,
|
|
89
|
-
onError,
|
|
90
|
-
onLoad: onLoadEnd,
|
|
91
|
-
fallback: /* @__PURE__ */ jsx(Fallback, {})
|
|
92
|
-
});
|
|
93
|
-
return /* @__PURE__ */ jsx(SvgXml, {
|
|
94
|
-
testID,
|
|
95
|
-
xml: data,
|
|
96
|
-
style,
|
|
97
|
-
...svgStyle,
|
|
98
|
-
fallback: /* @__PURE__ */ jsx(Fallback, {})
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/Image.tsx
|
|
104
|
-
/**
|
|
105
|
-
* @public
|
|
106
|
-
* @category UI
|
|
107
|
-
* @name Image
|
|
108
|
-
* @description You can use the `Image` component to load and render bitmap images (such as PNG, JPG) or vector images (SVG). It automatically renders with the appropriate method depending on the image format.
|
|
109
|
-
* @link https://github.com/DylanVann/react-native-fast-image/tree/v8.6.3/README.md
|
|
110
|
-
*
|
|
111
|
-
* @param {object} [props] - The `props` object passed to the component.
|
|
112
|
-
* @param {object} [props.style] - An object that defines the style for the image component. It can include layout-related properties like `width` and `height`.
|
|
113
|
-
* @param {object} [props.source] - An object containing information about the image resource to load.
|
|
114
|
-
* @param {string} [props.source.uri] - The URI address representing the image resource to load.
|
|
115
|
-
* @param {'immutable' | 'web' | 'cacheOnly'} [props.source.cache = 'immutable'] - An option to set the image caching strategy. This applies only to bitmap images. The default value is `immutable`.
|
|
116
|
-
* @param {() => void} [props.onLoadStart] - A callback function that is called when image loading starts.
|
|
117
|
-
* @param {() => void} [props.onLoadEnd] - A callback function that is called when image loading finishes.
|
|
118
|
-
* @param {() => void} [props.onError] - A callback function that is called when an error occurs during image loading.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ### Example: Loading and rendering an image
|
|
122
|
-
*
|
|
123
|
-
* The following example shows how to load bitmap and vector image resources, and how to print an error message to `console.log` if an error occurs.
|
|
124
|
-
*
|
|
125
|
-
* ```tsx
|
|
126
|
-
* import { Image } from '@granite-js/react-native';
|
|
127
|
-
* import { View } from 'react-native';
|
|
128
|
-
*
|
|
129
|
-
* export function ImageExample() {
|
|
130
|
-
* return (
|
|
131
|
-
* <View>
|
|
132
|
-
* <Image
|
|
133
|
-
* source={{ uri: 'my-image-link' }}
|
|
134
|
-
* style={{
|
|
135
|
-
* width: 300,
|
|
136
|
-
* height: 300,
|
|
137
|
-
* borderWidth: 1,
|
|
138
|
-
* }}
|
|
139
|
-
* onError={() => {
|
|
140
|
-
* console.log('Failed to load image');
|
|
141
|
-
* }}
|
|
142
|
-
* />
|
|
143
|
-
*
|
|
144
|
-
* <Image
|
|
145
|
-
* source={{ uri: 'my-svg-link' }}
|
|
146
|
-
* style={{
|
|
147
|
-
* width: 300,
|
|
148
|
-
* height: 300,
|
|
149
|
-
* borderWidth: 1,
|
|
150
|
-
* }}
|
|
151
|
-
* onError={() => {
|
|
152
|
-
* console.log('Failed to load image');
|
|
153
|
-
* }}
|
|
154
|
-
* />
|
|
155
|
-
* </View>
|
|
156
|
-
* );
|
|
157
|
-
* }
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
function Image(props) {
|
|
161
|
-
if (typeof props.source === "object" && props.source.uri?.endsWith(".svg")) {
|
|
162
|
-
const style = StyleSheet.flatten(props.style);
|
|
163
|
-
const width = style?.width;
|
|
164
|
-
const height = style?.height;
|
|
165
|
-
return /* @__PURE__ */ jsx(SvgImage, {
|
|
166
|
-
testID: props.testID,
|
|
167
|
-
url: props.source.uri,
|
|
168
|
-
width,
|
|
169
|
-
height,
|
|
170
|
-
style: props.style,
|
|
171
|
-
onLoadStart: props.onLoadStart,
|
|
172
|
-
onLoadEnd: props.onLoadEnd,
|
|
173
|
-
onError: props.onError
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
return /* @__PURE__ */ jsx(FastImage, { ...props });
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
export { Image };
|