@amazon-devices/expo-image 2.0.1758683737

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.
Files changed (289) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +285 -0
  3. package/CMakeLists.txt +91 -0
  4. package/LICENSE +7 -0
  5. package/README.kepler.md +123 -0
  6. package/README.md +54 -0
  7. package/THIRD_PARTY_NOTICES.txt +24 -0
  8. package/android/build.gradle +124 -0
  9. package/android/proguard-rules.pro +28 -0
  10. package/android/src/main/AndroidManifest.xml +15 -0
  11. package/android/src/main/java/expo/modules/image/Exceptions.kt +9 -0
  12. package/android/src/main/java/expo/modules/image/ExpoImageAppGlideModule.kt +19 -0
  13. package/android/src/main/java/expo/modules/image/ExpoImageModule.kt +192 -0
  14. package/android/src/main/java/expo/modules/image/ExpoImageView.kt +220 -0
  15. package/android/src/main/java/expo/modules/image/ExpoImageViewWrapper.kt +652 -0
  16. package/android/src/main/java/expo/modules/image/GlideModel.kt +73 -0
  17. package/android/src/main/java/expo/modules/image/ImageUtils.kt +50 -0
  18. package/android/src/main/java/expo/modules/image/ImageViewWrapperTarget.kt +313 -0
  19. package/android/src/main/java/expo/modules/image/ResourceIdHelper.kt +47 -0
  20. package/android/src/main/java/expo/modules/image/ThumbnailRequestCoordinatorExtension.kt +21 -0
  21. package/android/src/main/java/expo/modules/image/YogaUtils.kt +20 -0
  22. package/android/src/main/java/expo/modules/image/blurhash/BlurHashFetcher.kt +32 -0
  23. package/android/src/main/java/expo/modules/image/blurhash/BlurhashDecoder.kt +189 -0
  24. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoader.kt +30 -0
  25. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoaderFactory.kt +14 -0
  26. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModule.kt +17 -0
  27. package/android/src/main/java/expo/modules/image/dataurls/Base64DataFetcher.kt +27 -0
  28. package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoader.kt +24 -0
  29. package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoaderFactory.kt +12 -0
  30. package/android/src/main/java/expo/modules/image/dataurls/Base64Module.kt +16 -0
  31. package/android/src/main/java/expo/modules/image/drawing/OutlineProvider.kt +201 -0
  32. package/android/src/main/java/expo/modules/image/enums/ContentFit.kt +89 -0
  33. package/android/src/main/java/expo/modules/image/enums/ImageCacheType.kt +14 -0
  34. package/android/src/main/java/expo/modules/image/enums/Priority.kt +15 -0
  35. package/android/src/main/java/expo/modules/image/events/GlideRequestListener.kt +64 -0
  36. package/android/src/main/java/expo/modules/image/events/OkHttpProgressListener.kt +26 -0
  37. package/android/src/main/java/expo/modules/image/okhttp/ExpoImageOkHttpClientGlideModule.kt +80 -0
  38. package/android/src/main/java/expo/modules/image/okhttp/GlideUrlWrapperLoader.kt +55 -0
  39. package/android/src/main/java/expo/modules/image/records/CachePolicy.kt +10 -0
  40. package/android/src/main/java/expo/modules/image/records/ContentPosition.kt +89 -0
  41. package/android/src/main/java/expo/modules/image/records/ImageTransition.kt +8 -0
  42. package/android/src/main/java/expo/modules/image/records/SourceMap.kt +160 -0
  43. package/android/src/main/java/expo/modules/image/records/events.kt +25 -0
  44. package/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt +33 -0
  45. package/android/src/main/java/expo/modules/image/svg/SVGDrawableTranscoder.kt +37 -0
  46. package/android/src/main/java/expo/modules/image/svg/SVGModule.kt +26 -0
  47. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashDecoder.kt +365 -0
  48. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashFetcher.kt +31 -0
  49. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoader.kt +26 -0
  50. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoaderFactory.kt +14 -0
  51. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModule.kt +17 -0
  52. package/build/ExpoImage.d.ts +15 -0
  53. package/build/ExpoImage.d.ts.map +1 -0
  54. package/build/ExpoImage.js +75 -0
  55. package/build/ExpoImage.js.map +1 -0
  56. package/build/ExpoImage.kepler.d.ts +23 -0
  57. package/build/ExpoImage.kepler.d.ts.map +1 -0
  58. package/build/ExpoImage.kepler.js +71 -0
  59. package/build/ExpoImage.kepler.js.map +1 -0
  60. package/build/ExpoImage.web.d.ts +9 -0
  61. package/build/ExpoImage.web.d.ts.map +1 -0
  62. package/build/ExpoImage.web.js +90 -0
  63. package/build/ExpoImage.web.js.map +1 -0
  64. package/build/ExpoImageModules.d.ts +3 -0
  65. package/build/ExpoImageModules.d.ts.map +1 -0
  66. package/build/ExpoImageModules.js +4 -0
  67. package/build/ExpoImageModules.js.map +1 -0
  68. package/build/ExpoImageModules.kepler.d.ts +6 -0
  69. package/build/ExpoImageModules.kepler.d.ts.map +1 -0
  70. package/build/ExpoImageModules.kepler.js +5 -0
  71. package/build/ExpoImageModules.kepler.js.map +1 -0
  72. package/build/Image.d.ts +30 -0
  73. package/build/Image.d.ts.map +1 -0
  74. package/build/Image.js +49 -0
  75. package/build/Image.js.map +1 -0
  76. package/build/Image.types.d.ts +374 -0
  77. package/build/Image.types.d.ts.map +1 -0
  78. package/build/Image.types.js +2 -0
  79. package/build/Image.types.js.map +1 -0
  80. package/build/ImageBackground.d.ts +6 -0
  81. package/build/ImageBackground.d.ts.map +1 -0
  82. package/build/ImageBackground.js +13 -0
  83. package/build/ImageBackground.js.map +1 -0
  84. package/build/ImageViewNativeComponent.d.ts +20 -0
  85. package/build/ImageViewNativeComponent.d.ts.map +1 -0
  86. package/build/ImageViewNativeComponent.js +42 -0
  87. package/build/ImageViewNativeComponent.js.map +1 -0
  88. package/build/NativeImageLoaderKepler.d.ts +18 -0
  89. package/build/NativeImageLoaderKepler.d.ts.map +1 -0
  90. package/build/NativeImageLoaderKepler.js +3 -0
  91. package/build/NativeImageLoaderKepler.js.map +1 -0
  92. package/build/fabric/registerNativeComponent.d.ts +15 -0
  93. package/build/fabric/registerNativeComponent.d.ts.map +1 -0
  94. package/build/fabric/registerNativeComponent.js +47 -0
  95. package/build/fabric/registerNativeComponent.js.map +1 -0
  96. package/build/index.d.ts +4 -0
  97. package/build/index.d.ts.map +1 -0
  98. package/build/index.js +4 -0
  99. package/build/index.js.map +1 -0
  100. package/build/utils/AssetSourceResolver.web.d.ts +24 -0
  101. package/build/utils/AssetSourceResolver.web.d.ts.map +1 -0
  102. package/build/utils/AssetSourceResolver.web.js +67 -0
  103. package/build/utils/AssetSourceResolver.web.js.map +1 -0
  104. package/build/utils/blurhash/base83.d.ts +3 -0
  105. package/build/utils/blurhash/base83.d.ts.map +1 -0
  106. package/build/utils/blurhash/base83.js +103 -0
  107. package/build/utils/blurhash/base83.js.map +1 -0
  108. package/build/utils/blurhash/decode.d.ts +7 -0
  109. package/build/utils/blurhash/decode.d.ts.map +1 -0
  110. package/build/utils/blurhash/decode.js +92 -0
  111. package/build/utils/blurhash/decode.js.map +1 -0
  112. package/build/utils/blurhash/error.d.ts +4 -0
  113. package/build/utils/blurhash/error.d.ts.map +1 -0
  114. package/build/utils/blurhash/error.js +8 -0
  115. package/build/utils/blurhash/error.js.map +1 -0
  116. package/build/utils/blurhash/useBlurhash.d.ts +8 -0
  117. package/build/utils/blurhash/useBlurhash.d.ts.map +1 -0
  118. package/build/utils/blurhash/useBlurhash.js +64 -0
  119. package/build/utils/blurhash/useBlurhash.js.map +1 -0
  120. package/build/utils/blurhash/utils.d.ts +5 -0
  121. package/build/utils/blurhash/utils.d.ts.map +1 -0
  122. package/build/utils/blurhash/utils.js +21 -0
  123. package/build/utils/blurhash/utils.js.map +1 -0
  124. package/build/utils/resolveAssetSource.d.ts +3 -0
  125. package/build/utils/resolveAssetSource.d.ts.map +1 -0
  126. package/build/utils/resolveAssetSource.js +3 -0
  127. package/build/utils/resolveAssetSource.js.map +1 -0
  128. package/build/utils/resolveAssetSource.web.d.ts +9 -0
  129. package/build/utils/resolveAssetSource.web.d.ts.map +1 -0
  130. package/build/utils/resolveAssetSource.web.js +31 -0
  131. package/build/utils/resolveAssetSource.web.js.map +1 -0
  132. package/build/utils/resolveHashString.d.ts +14 -0
  133. package/build/utils/resolveHashString.d.ts.map +1 -0
  134. package/build/utils/resolveHashString.js +31 -0
  135. package/build/utils/resolveHashString.js.map +1 -0
  136. package/build/utils/resolveHashString.web.d.ts +20 -0
  137. package/build/utils/resolveHashString.web.d.ts.map +1 -0
  138. package/build/utils/resolveHashString.web.js +31 -0
  139. package/build/utils/resolveHashString.web.js.map +1 -0
  140. package/build/utils/resolveSources.d.ts +8 -0
  141. package/build/utils/resolveSources.d.ts.map +1 -0
  142. package/build/utils/resolveSources.js +45 -0
  143. package/build/utils/resolveSources.js.map +1 -0
  144. package/build/utils/thumbhash/thumbhash.d.ts +66 -0
  145. package/build/utils/thumbhash/thumbhash.d.ts.map +1 -0
  146. package/build/utils/thumbhash/thumbhash.js +338 -0
  147. package/build/utils/thumbhash/thumbhash.js.map +1 -0
  148. package/build/utils.d.ts +17 -0
  149. package/build/utils.d.ts.map +1 -0
  150. package/build/utils.js +85 -0
  151. package/build/utils.js.map +1 -0
  152. package/build/web/AnimationManager.d.ts +37 -0
  153. package/build/web/AnimationManager.d.ts.map +1 -0
  154. package/build/web/AnimationManager.js +155 -0
  155. package/build/web/AnimationManager.js.map +1 -0
  156. package/build/web/ColorTintFilter.d.ts +12 -0
  157. package/build/web/ColorTintFilter.d.ts.map +1 -0
  158. package/build/web/ColorTintFilter.js +30 -0
  159. package/build/web/ColorTintFilter.js.map +1 -0
  160. package/build/web/ImageWrapper.d.ts +5 -0
  161. package/build/web/ImageWrapper.d.ts.map +1 -0
  162. package/build/web/ImageWrapper.js +44 -0
  163. package/build/web/ImageWrapper.js.map +1 -0
  164. package/build/web/ImageWrapper.types.d.ts +29 -0
  165. package/build/web/ImageWrapper.types.d.ts.map +1 -0
  166. package/build/web/ImageWrapper.types.js +2 -0
  167. package/build/web/ImageWrapper.types.js.map +1 -0
  168. package/build/web/getImageWrapperEventHandler.d.ts +8 -0
  169. package/build/web/getImageWrapperEventHandler.d.ts.map +1 -0
  170. package/build/web/getImageWrapperEventHandler.js +25 -0
  171. package/build/web/getImageWrapperEventHandler.js.map +1 -0
  172. package/build/web/hooks.d.ts +13 -0
  173. package/build/web/hooks.d.ts.map +1 -0
  174. package/build/web/hooks.js +58 -0
  175. package/build/web/hooks.js.map +1 -0
  176. package/build/web/imageStyles.d.ts +2 -0
  177. package/build/web/imageStyles.d.ts.map +1 -0
  178. package/build/web/imageStyles.js +137 -0
  179. package/build/web/imageStyles.js.map +1 -0
  180. package/build/web/positioning.d.ts +11 -0
  181. package/build/web/positioning.d.ts.map +1 -0
  182. package/build/web/positioning.js +35 -0
  183. package/build/web/positioning.js.map +1 -0
  184. package/build/web/useSourceSelection.d.ts +14 -0
  185. package/build/web/useSourceSelection.d.ts.map +1 -0
  186. package/build/web/useSourceSelection.js +98 -0
  187. package/build/web/useSourceSelection.js.map +1 -0
  188. package/expo-module.config.json +9 -0
  189. package/ios/Blurhash.swift +326 -0
  190. package/ios/BlurhashLoader.swift +52 -0
  191. package/ios/ContentFit.swift +55 -0
  192. package/ios/ContentPosition.swift +108 -0
  193. package/ios/ExpoImage.podspec +30 -0
  194. package/ios/ImageCachePolicy.swift +24 -0
  195. package/ios/ImageCacheType.swift +21 -0
  196. package/ios/ImageModule.swift +127 -0
  197. package/ios/ImagePriority.swift +22 -0
  198. package/ios/ImageSource.swift +44 -0
  199. package/ios/ImageTransition.swift +67 -0
  200. package/ios/ImageUtils.swift +227 -0
  201. package/ios/ImageView.swift +469 -0
  202. package/ios/Loaders/PhotoLibraryAssetLoader.swift +146 -0
  203. package/ios/Thumbhash.swift +550 -0
  204. package/ios/ThumbhashLoader.swift +53 -0
  205. package/jest.config.js +3 -0
  206. package/kepler/ExpoImage.cpp +63 -0
  207. package/kepler/ExpoImage.h +29 -0
  208. package/kepler/ExpoImageCacheHandler.cpp +15 -0
  209. package/kepler/ExpoImageCacheHandler.h +28 -0
  210. package/kepler/ExpoImageComponent.cpp +579 -0
  211. package/kepler/ExpoImageComponent.h +199 -0
  212. package/kepler/ImageWrapper/BlurhashImageWrapper.cpp +37 -0
  213. package/kepler/ImageWrapper/BlurhashImageWrapper.h +23 -0
  214. package/kepler/ImageWrapper/CacheImageWrapper.cpp +80 -0
  215. package/kepler/ImageWrapper/CacheImageWrapper.h +41 -0
  216. package/kepler/ImageWrapper/HashImageWrapper.cpp +21 -0
  217. package/kepler/ImageWrapper/HashImageWrapper.h +22 -0
  218. package/kepler/ImageWrapper/ImageWrapper.cpp +24 -0
  219. package/kepler/ImageWrapper/ImageWrapper.h +33 -0
  220. package/kepler/ImageWrapper/LocalImageWrapper.cpp +61 -0
  221. package/kepler/ImageWrapper/LocalImageWrapper.h +30 -0
  222. package/kepler/ImageWrapper/ThumbhashImageWrapper.cpp +33 -0
  223. package/kepler/ImageWrapper/ThumbhashImageWrapper.h +20 -0
  224. package/kepler/KeplerImageViewComponent.h +64 -0
  225. package/kepler/KeplerInit.cpp +35 -0
  226. package/kepler/blurhash/common.h +32 -0
  227. package/kepler/blurhash/decode.cpp +187 -0
  228. package/kepler/blurhash/decode.h +58 -0
  229. package/kepler/contentposition/ImageContentPosition.cpp +86 -0
  230. package/kepler/contentposition/ImageContentPosition.h +48 -0
  231. package/kepler/enums/ImageContentFit.h +17 -0
  232. package/kepler/enums/ImagePriority.h +17 -0
  233. package/kepler/managers/ExpoImageManager.cpp +38 -0
  234. package/kepler/managers/ExpoImageManager.h +23 -0
  235. package/kepler/test/ExpoImage.cpp +73 -0
  236. package/kepler/test/ExpoImageComponent.cpp +290 -0
  237. package/kepler/test/blurhash/decode.cpp +39 -0
  238. package/kepler/test/contentposition/ImageContentPosition.cpp +100 -0
  239. package/kepler/test/managers/ExpoImageManager.cpp +39 -0
  240. package/kepler/test/thumbhash/decode.cpp +18 -0
  241. package/kepler/test/utils/LoaderDelegate.cpp +130 -0
  242. package/kepler/thumbhash/decode.cpp +166 -0
  243. package/kepler/thumbhash/decode.h +22 -0
  244. package/kepler/utils/PlaceholderImageLoaderDelegate.cpp +26 -0
  245. package/kepler/utils/PlaceholderImageLoaderDelegate.h +26 -0
  246. package/kepler/utils/PrefetchImageLoaderDelegate.cpp +55 -0
  247. package/kepler/utils/PrefetchImageLoaderDelegate.h +35 -0
  248. package/kepler/utils/SourceImageLoaderDelegate.cpp +47 -0
  249. package/kepler/utils/SourceImageLoaderDelegate.h +42 -0
  250. package/kepler/utils/SourceImageLoaderDelegateEmitter.cpp +15 -0
  251. package/kepler/utils/SourceImageLoaderDelegateEmitter.h +28 -0
  252. package/kepler-compatibility.json +8 -0
  253. package/package.json +1 -0
  254. package/react-native.config.js +22 -0
  255. package/src/ExpoImage.kepler.tsx +119 -0
  256. package/src/ExpoImage.tsx +119 -0
  257. package/src/ExpoImage.web.tsx +155 -0
  258. package/src/ExpoImageModules.kepler.ts +7 -0
  259. package/src/ExpoImageModules.ts +4 -0
  260. package/src/Image.tsx +82 -0
  261. package/src/Image.types.ts +450 -0
  262. package/src/ImageBackground.tsx +18 -0
  263. package/src/ImageViewNativeComponent.ts +59 -0
  264. package/src/NativeImageLoaderKepler.ts +22 -0
  265. package/src/fabric/registerNativeComponent.ts +70 -0
  266. package/src/index.ts +3 -0
  267. package/src/utils/AssetSourceResolver.web.ts +88 -0
  268. package/src/utils/blurhash/base83.ts +104 -0
  269. package/src/utils/blurhash/decode.ts +114 -0
  270. package/src/utils/blurhash/error.ts +7 -0
  271. package/src/utils/blurhash/useBlurhash.tsx +81 -0
  272. package/src/utils/blurhash/utils.ts +21 -0
  273. package/src/utils/resolveAssetSource.tsx +3 -0
  274. package/src/utils/resolveAssetSource.web.ts +40 -0
  275. package/src/utils/resolveHashString.tsx +36 -0
  276. package/src/utils/resolveHashString.web.tsx +33 -0
  277. package/src/utils/resolveSources.tsx +48 -0
  278. package/src/utils/thumbhash/thumbhash.ts +387 -0
  279. package/src/utils.ts +109 -0
  280. package/src/web/AnimationManager.tsx +224 -0
  281. package/src/web/ColorTintFilter.tsx +36 -0
  282. package/src/web/ImageWrapper.tsx +85 -0
  283. package/src/web/ImageWrapper.types.ts +36 -0
  284. package/src/web/getImageWrapperEventHandler.ts +29 -0
  285. package/src/web/hooks.ts +72 -0
  286. package/src/web/imageStyles.tsx +136 -0
  287. package/src/web/positioning.ts +48 -0
  288. package/src/web/useSourceSelection.ts +151 -0
  289. package/tsconfig.json +9 -0
@@ -0,0 +1,450 @@
1
+ import { ImageStyle as RNImageStyle, ViewProps, StyleProp, ViewStyle } from 'react-native';
2
+
3
+ export type ImageSource = {
4
+ /**
5
+ * A string representing the resource identifier for the image,
6
+ * which could be an http address, a local file path, or the name of a static image resource.
7
+ */
8
+ uri?: string;
9
+ /**
10
+ * An object representing the HTTP headers to send along with the request for a remote image.
11
+ * On web requires the `Access-Control-Allow-Origin` header returned by the server to include the current domain.
12
+ */
13
+ headers?: Record<string, string>;
14
+ /**
15
+ * Can be specified if known at build time, in which case the value
16
+ * will be used to set the default `<Image/>` component dimension
17
+ */
18
+ width?: number;
19
+ /**
20
+ * Can be specified if known at build time, in which case the value
21
+ * will be used to set the default `<Image/>` component dimension
22
+ */
23
+ height?: number;
24
+
25
+ /**
26
+ * The blurhash string to use to generate the image. You can read more about the blurhash
27
+ * on [`woltapp/blurhash`](https://github.com/woltapp/blurhash) repo. Ignored when `uri` is provided.
28
+ * When using the blurhash, you should also provide `width` and `height` (higher values reduce performance),
29
+ * otherwise their default value is `16`.
30
+ */
31
+ blurhash?: string;
32
+
33
+ /**
34
+ * The thumbhash string to use to generate the image placeholder. You can read more about thumbhash
35
+ * on the [`thumbhash website`](https://evanw.github.io/thumbhash/). Ignored when `uri` is provided.
36
+ */
37
+ thumbhash?: string;
38
+
39
+ /**
40
+ * The cache key used to query and store this specific image.
41
+ * If not provided, the `uri` is used also as the cache key.
42
+ */
43
+ cacheKey?: string;
44
+ /**
45
+ * The max width of the viewport for which this source should be selected.
46
+ * Has no effect if `source` prop is not an array or has only 1 element.
47
+ * Has no effect if `responsivePolicy` is not set to `static`.
48
+ * Ignored if `blurhash` or `thumbhash` is provided (image hashes are never selected if passed in an array).
49
+ * @platform web
50
+ */
51
+ webMaxViewportWidth?: number;
52
+ };
53
+
54
+ /**
55
+ * @hidden
56
+ */
57
+ export type ImageStyle = RNImageStyle;
58
+
59
+ /**
60
+ * Determines how the image should be resized to fit its container.
61
+ * @hidden Described in the {@link ImageProps['contentFit']}
62
+ */
63
+ export type ImageContentFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
64
+
65
+ /**
66
+ * Some props are from React Native Image that Expo Image supports (more or less) for easier migration,
67
+ * but all of them are deprecated and might be removed in the future.
68
+ */
69
+ export interface ImageProps extends ViewProps {
70
+ /** @hidden */
71
+ style?: StyleProp<RNImageStyle>;
72
+
73
+ /**
74
+ * The image source, either a remote URL, a local file resource or a number that is the result of the `require()` function.
75
+ * When provided as an array of sources, the source that fits best into the container size and is closest to the screen scale
76
+ * will be chosen. In this case it is important to provide `width`, `height` and `scale` properties.
77
+ */
78
+ source?: ImageSource | string | number | ImageSource[] | string[] | null;
79
+
80
+ /**
81
+ * An image to display while loading the proper image and no image has been displayed yet or the source is unset.
82
+ */
83
+ placeholder?: ImageSource | string | number | ImageSource[] | string[] | null;
84
+
85
+ /**
86
+ * Determines how the image should be resized to fit its container. This property tells the image to fill the container
87
+ * in a variety of ways; such as "preserve that aspect ratio" or "stretch up and take up as much space as possible".
88
+ * It mirrors the CSS [`object-fit`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property.
89
+ *
90
+ * - `'cover'` - The image is sized to maintain its aspect ratio while filling the container box.
91
+ * If the image's aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.
92
+ *
93
+ * - `'contain'` - The image is scaled down or up to maintain its aspect ratio while fitting within the container box.
94
+ *
95
+ * - `'fill'` - The image is sized to entirely fill the container box. If necessary, the image will be stretched or squished to fit.
96
+ *
97
+ * - `'none'` - The image is not resized and is centered by default.
98
+ * When specified, the exact position can be controlled with [`contentPosition`](#contentposition) prop.
99
+ *
100
+ * - `'scale-down'` - The image is sized as if `none` or `contain` were specified, whichever would result in a smaller concrete image size.
101
+ *
102
+ * @default 'cover'
103
+ */
104
+ contentFit?: ImageContentFit;
105
+
106
+ /**
107
+ * Determines how the placeholder should be resized to fit its container. Available resize modes are the same as for the [`contentFit`](#contentfit) prop.
108
+ * @default 'scale-down'
109
+ */
110
+ placeholderContentFit?: ImageContentFit;
111
+
112
+ /**
113
+ * It is used together with [`contentFit`](#contentfit) to specify how the image should be positioned with x/y coordinates inside its own container.
114
+ * An equivalent of the CSS [`object-position`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) property.
115
+ * @default 'center'
116
+ */
117
+ contentPosition?: ImageContentPosition;
118
+
119
+ /**
120
+ * Describes how the image view should transition the contents when switching the image source.\
121
+ * If provided as a number, it is the duration in milliseconds of the `'cross-dissolve'` effect.
122
+ */
123
+ transition?: ImageTransition | number | null;
124
+
125
+ /**
126
+ * The radius of the blur in points, `0` means no blur effect.
127
+ * This effect is not applied to placeholders.
128
+ * @default 0
129
+ */
130
+ blurRadius?: number;
131
+
132
+ /**
133
+ * A color used to tint template images (a bitmap image where only the opacity matters).
134
+ * The color is applied to every non-transparent pixel, causing the image’s shape to adopt that color.
135
+ * This effect is not applied to placeholders.
136
+ * @default null
137
+ */
138
+ tintColor?: string | null;
139
+
140
+ /**
141
+ * Priorities for completing loads. If more than one load is queued at a time,
142
+ * the load with the higher priority will be started first.
143
+ * Priorities are considered best effort, there are no guarantees about the order in which loads will start or finish.
144
+ * @default 'normal'
145
+ */
146
+ priority?: 'low' | 'normal' | 'high' | null;
147
+
148
+ /**
149
+ * Determines whether to cache the image and where: on the disk, in the memory or both.
150
+ *
151
+ * - `'none'` - Image is not cached at all.
152
+ *
153
+ * - `'disk'` - Image is queried from the disk cache if exists, otherwise it's downloaded and then stored on the disk.
154
+ *
155
+ * - `'memory'` - Image is cached in memory. Might be useful when you render a high-resolution picture many times.
156
+ * Memory cache may be purged very quickly to prevent high memory usage and the risk of out of memory exceptions.
157
+ *
158
+ * - `'memory-disk'` - Image is cached in memory, but with a fallback to the disk cache.
159
+ *
160
+ * @default 'disk'
161
+ */
162
+ cachePolicy?: 'none' | 'disk' | 'memory' | 'memory-disk' | /** @hidden */ null;
163
+
164
+ /**
165
+ * Controls the selection of the image source based on the container or viewport size on the web.
166
+ *
167
+ * If set to `'static'`, the browser selects the correct source based on user's viewport width. Works with static rendering.
168
+ * Make sure to set the `'webMaxViewportWidth'` property on each source for best results.
169
+ * For example, if an image occupies 1/3 of the screen width, set the `'webMaxViewportWidth'` to 3x the image width.
170
+ * The source with the largest `'webMaxViewportWidth'` is used even for larger viewports.
171
+ *
172
+ * If set to `'initial'`, the component will select the correct source during mount based on container size. Does not work with static rendering.
173
+ *
174
+ * If set to `'live'`, the component will select the correct source on every resize based on container size. Does not work with static rendering.
175
+ *
176
+ * @default 'static'
177
+ * @platform web
178
+ */
179
+ responsivePolicy?: 'live' | 'initial' | 'static';
180
+
181
+ /**
182
+ * Changing this prop resets the image view content to blank or a placeholder before loading and rendering the final image.
183
+ * This is especially useful for any kinds of recycling views like [FlashList](https://github.com/shopify/flash-list)
184
+ * to prevent showing the previous source before the new one fully loads.
185
+ * @default null
186
+ * @platform android
187
+ * @platform ios
188
+ */
189
+ recyclingKey?: string | null;
190
+
191
+ /**
192
+ * Called when the image starts to load.
193
+ */
194
+ onLoadStart?: () => void;
195
+
196
+ /**
197
+ * Called when the image load completes successfully.
198
+ */
199
+ onLoad?: (event: ImageLoadEventData) => void;
200
+
201
+ /**
202
+ * Called when the image is loading. Can be called multiple times before the image has finished loading.
203
+ * The event object provides details on how many bytes were loaded so far and what's the expected total size.
204
+ */
205
+ onProgress?: (event: ImageProgressEventData) => void;
206
+
207
+ /**
208
+ * Called on an image fetching error.
209
+ */
210
+ onError?: (event: ImageErrorEventData) => void;
211
+
212
+ /**
213
+ * Called when the image load either succeeds or fails.
214
+ */
215
+ onLoadEnd?: () => void;
216
+
217
+ // DEPRECATED
218
+
219
+ /**
220
+ * @deprecated Provides compatibility for [`defaultSource` from React Native Image](https://reactnative.dev/docs/image#defaultsource).
221
+ * Use [`placeholder`](#placeholder) prop instead.
222
+ */
223
+ defaultSource?: ImageSource | null;
224
+
225
+ /**
226
+ * @deprecated Provides compatibility for [`loadingIndicatorSource` from React Native Image](https://reactnative.dev/docs/image#loadingindicatorsource).
227
+ * Use [`placeholder`](#placeholder) prop instead.
228
+ */
229
+ loadingIndicatorSource?: ImageSource | null;
230
+
231
+ /**
232
+ * @deprecated Provides compatibility for [`resizeMode` from React Native Image](https://reactnative.dev/docs/image#resizemode).
233
+ * Note that `"repeat"` option is not supported at all.
234
+ * Use the more powerful [`contentFit`](#contentfit) and [`contentPosition`](#contentposition) props instead.
235
+ */
236
+ resizeMode?: 'cover' | 'contain' | 'stretch' | 'repeat' | 'center';
237
+
238
+ /**
239
+ * @deprecated Provides compatibility for [`fadeDuration` from React Native Image](https://reactnative.dev/docs/image#fadeduration-android).
240
+ * Instead use [`transition`](#transition) with the provided duration.
241
+ */
242
+ fadeDuration?: number;
243
+
244
+ /**
245
+ * Whether this View should be focusable with a non-touch input device and receive focus with a hardware keyboard.
246
+ * @default false
247
+ * @platform android
248
+ */
249
+ focusable?: boolean;
250
+
251
+ /**
252
+ * When true, indicates that the view is an accessibility element.
253
+ * When a view is an accessibility element, it groups its children into a single selectable component.
254
+ *
255
+ * On Android, the `accessible` property will be translated into the native `isScreenReaderFocusable`,
256
+ * so it's only affecting the screen readers behaviour.
257
+ * @default false
258
+ * @platform android
259
+ * @platform ios
260
+ */
261
+ accessible?: boolean;
262
+
263
+ /**
264
+ * The text that's read by the screen reader when the user interacts with the image. Sets the the `alt` tag on web which is used for web crawlers and link traversal.
265
+ * @default undefined
266
+ */
267
+ accessibilityLabel?: string;
268
+
269
+ /**
270
+ * The text that's read by the screen reader when the user interacts with the image. Sets the the `alt` tag on web which is used for web crawlers and link traversal. Is an alias for `accessibilityLabel`.
271
+ *
272
+ * @alias accessibilityLabel
273
+ * @default undefined
274
+ */
275
+ alt?: string;
276
+
277
+ /**
278
+ * Enables Live Text interaction with the image. Check official [Apple documentation](https://developer.apple.com/documentation/visionkit/enabling_live_text_interactions_with_images) for more details.
279
+ * @default false
280
+ * @platform ios 16.0+
281
+ */
282
+ enableLiveTextInteraction?: boolean;
283
+
284
+ /**
285
+ * Whether the image should be downscaled to match the size of the view container.
286
+ * Turning off this functionality could negatively impact the application's performance, particularly when working with large assets.
287
+ * However, it would result in smoother image resizing, and end-users would always have access to the highest possible asset quality.
288
+ *
289
+ * Downscaling is never used when the `contentFit` prop is set to `none` or `fill`.
290
+ * @default true
291
+ * @platform android
292
+ */
293
+ allowDownscaling?: boolean;
294
+ }
295
+
296
+ /**
297
+ * It narrows down some props to types expected by the native/web side.
298
+ * @hidden
299
+ */
300
+ export interface ImageNativeProps extends ImageProps {
301
+ style?: RNImageStyle;
302
+ source?: ImageSource[];
303
+ placeholder?: ImageSource[];
304
+ contentPosition?: ImageContentPositionObject;
305
+ transition?: ImageTransition | null;
306
+ }
307
+
308
+ /**
309
+ * A value that represents the relative position of a single axis.
310
+ *
311
+ * If `number`, it is a distance in points (logical pixels) from the respective edge.\
312
+ * If `string`, it must be a percentage value where `'100%'` is the difference in size between the container and the image along the respective axis,
313
+ * or `'center'` which is an alias for `'50%'` that is the default value. You can read more regarding percentages on the MDN docs for
314
+ * [`background-position`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position#regarding_percentages) that describes this concept well.
315
+ */
316
+ export type ImageContentPositionValue = number | string | `${number}%` | `${number}` | 'center';
317
+
318
+ // eslint-disable
319
+ // prettier-ignore
320
+ /**
321
+ * Specifies the position of the image inside its container. One value controls the x-axis and the second value controls the y-axis.
322
+ *
323
+ * Additionally, it supports stringified shorthand form that specifies the edges to which to align the image content:\
324
+ * `'center'`, `'top'`, `'right'`, `'bottom'`, `'left'`, `'top center'`, `'top right'`, `'top left'`, `'right center'`, `'right top'`,
325
+ * `'right bottom'`, `'bottom center'`, `'bottom right'`, `'bottom left'`, `'left center'`, `'left top'`, `'left bottom'`.\
326
+ * If only one keyword is provided, then the other dimension is set to `'center'` (`'50%'`), so the image is placed in the middle of the specified edge.\
327
+ * As an example, `'top right'` is the same as `{ top: 0, right: 0 }` and `'bottom'` is the same as `{ bottom: 0, left: '50%' }`.
328
+ */
329
+ export type ImageContentPosition =
330
+ /**
331
+ * An object that positions the image relatively to the top-right corner.
332
+ */
333
+ {
334
+ top?: ImageContentPositionValue;
335
+ right?: ImageContentPositionValue;
336
+ } |
337
+ /**
338
+ * An object that positions the image relatively to the top-left corner.
339
+ */
340
+ {
341
+ top?: ImageContentPositionValue;
342
+ left?: ImageContentPositionValue;
343
+ } |
344
+ /**
345
+ * An object that positions the image relatively to the bottom-right corner.
346
+ */
347
+ {
348
+ bottom?: ImageContentPositionValue;
349
+ right?: ImageContentPositionValue;
350
+ } |
351
+ /**
352
+ * An object that positions the image relatively to the bottom-left corner.
353
+ */
354
+ {
355
+ bottom?: ImageContentPositionValue;
356
+ left?: ImageContentPositionValue;
357
+ }
358
+ | ImageContentPositionString;
359
+ // eslint-enable
360
+
361
+ export interface ImageBackgroundProps extends Omit<ImageProps, 'style'> {
362
+ /** The style of the image container */
363
+ style?: StyleProp<ViewStyle> | undefined;
364
+ /** Style object for the image */
365
+ imageStyle?: StyleProp<RNImageStyle> | undefined;
366
+ /** @hidden */
367
+ children?: React.ReactNode | undefined;
368
+ }
369
+
370
+ /**
371
+ * @hidden It's described as part of {@link ImageContentPosition}.
372
+ */
373
+ export type ImageContentPositionString =
374
+ | 'center'
375
+ | 'top'
376
+ | 'right'
377
+ | 'bottom'
378
+ | 'left'
379
+ | 'top center'
380
+ | 'top right'
381
+ | 'top left'
382
+ | 'right center'
383
+ | 'right top'
384
+ | 'right bottom'
385
+ | 'bottom center'
386
+ | 'bottom right'
387
+ | 'bottom left'
388
+ | 'left center'
389
+ | 'left top'
390
+ | 'left bottom';
391
+
392
+ type OnlyObject<T> = T extends object ? T : never;
393
+
394
+ /**
395
+ * @hidden It's a conditional type that matches only objects of {@link ImageContentPosition}.
396
+ */
397
+ export type ImageContentPositionObject = OnlyObject<ImageContentPosition>;
398
+
399
+ /**
400
+ * An object that describes the smooth transition when switching the image source.
401
+ */
402
+ export type ImageTransition = {
403
+ /**
404
+ * The duration of the transition in milliseconds.
405
+ * @default 0
406
+ */
407
+ duration?: number;
408
+
409
+ /**
410
+ * Specifies the speed curve of the transition effect and how intermediate values are calculated.
411
+ * @default 'ease-in-out'
412
+ */
413
+ timing?: 'ease-in-out' | 'ease-in' | 'ease-out' | 'linear';
414
+
415
+ /**
416
+ * An animation effect used for transition.
417
+ * @default 'cross-dissolve'
418
+ *
419
+ * On Android, only `'cross-dissolve'` is supported.
420
+ * On Web, `'curl-up'` and `'curl-down'` effects are not supported.
421
+ */
422
+ effect?:
423
+ | 'cross-dissolve'
424
+ | 'flip-from-top'
425
+ | 'flip-from-right'
426
+ | 'flip-from-bottom'
427
+ | 'flip-from-left'
428
+ | 'curl-up'
429
+ | 'curl-down'
430
+ | null;
431
+ };
432
+
433
+ export type ImageLoadEventData = {
434
+ cacheType: 'none' | 'disk' | 'memory';
435
+ source: {
436
+ url: string;
437
+ width: number;
438
+ height: number;
439
+ mediaType: string | null;
440
+ };
441
+ };
442
+
443
+ export type ImageProgressEventData = {
444
+ loaded: number;
445
+ total: number;
446
+ };
447
+
448
+ export type ImageErrorEventData = {
449
+ error: string;
450
+ };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+
4
+ import { Image } from './Image';
5
+ import { ImageBackgroundProps } from './Image.types';
6
+
7
+ export class ImageBackground extends React.PureComponent<ImageBackgroundProps> {
8
+ render() {
9
+ const { style, imageStyle, children, ...props } = this.props;
10
+
11
+ return (
12
+ <View style={style}>
13
+ <Image {...props} style={[StyleSheet.absoluteFill, imageStyle]} />
14
+ {children}
15
+ </View>
16
+ );
17
+ }
18
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ import { NativeSyntheticEvent, ProcessedColorValue } from 'react-native';
12
+
13
+ import registerNativeComponent from './fabric/registerNativeComponent';
14
+ import {
15
+ ImageNativeProps,
16
+ ImageErrorEventData,
17
+ ImageLoadEventData,
18
+ ImageProgressEventData,
19
+ } from './Image.types';
20
+
21
+ export type ImageViewNativeComponentProps = Omit<ImageNativeProps, 'tintColor' | 'onLoad' | 'onError' | 'onProgress'> & {
22
+ tintColor: ProcessedColorValue | null | undefined;
23
+ onLoad: (event: NativeSyntheticEvent<ImageLoadEventData>) => void;
24
+ onError: (event: NativeSyntheticEvent<ImageErrorEventData>) => void;
25
+ onProgress: (event: NativeSyntheticEvent<ImageProgressEventData>) => void;
26
+ };
27
+
28
+ const ImageViewNativeComponent = registerNativeComponent<ImageViewNativeComponentProps>('ExpoImageComponent', {
29
+ validAttributes: {
30
+ placeholder: true,
31
+ pointerEvents: true,
32
+ resizeMode: true,
33
+ contentFit: true,
34
+ contentPosition: true,
35
+ source: true,
36
+ placeholderContentFit: true,
37
+ transition: true,
38
+ blurRadius: true,
39
+ tintColor: true,
40
+ priority: true,
41
+ cachePolicy: true,
42
+ responsivePolicy: true,
43
+ recyclingKey: true,
44
+ onLoadStart: true,
45
+ onLoad: true,
46
+ onProgress: true,
47
+ onError: true,
48
+ onLoadEnd: true,
49
+ defaultSource: true,
50
+ loadingIndicatorSource: true,
51
+ fadeDuration: true,
52
+ alt: true,
53
+ accessibilityLabel: true,
54
+ enableLiveTextInteraction: true,
55
+ allowDownscaling: true,
56
+ },
57
+ });
58
+
59
+ export default ImageViewNativeComponent;
@@ -0,0 +1,22 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ abortRequest: (requestId: number) => void;
6
+ getConstants: () => object;
7
+ getSize: (uri: string) => Promise<{
8
+ width: number;
9
+ height: number;
10
+ }>;
11
+ getSizeWithHeaders: (
12
+ uri: string,
13
+ headers: object
14
+ ) => Promise<{
15
+ width: number;
16
+ height: number;
17
+ }>;
18
+ prefetchImage: (uri: string, requestId: number) => Promise<boolean>;
19
+ queryCache: (uris: string[]) => Promise<Record<string, 'memory' | 'disk' | 'disk/memory'>>;
20
+ }
21
+
22
+ export default TurboModuleRegistry.getEnforcing<Spec>('ImageLoader');
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * PROPRIETARY/CONFIDENTIAL
5
+ *
6
+ * Use is subject to license terms.
7
+ */
8
+
9
+ import { Platform } from 'react-native';
10
+ import type { HostComponent, ViewProps as VP } from 'react-native';
11
+ // @ts-ignore For some reason this is unknown
12
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
13
+ // @ts-ignore For some reason this is unknown
14
+ import register from 'react-native/Libraries/Utilities/registerGeneratedViewConfig';
15
+
16
+ type ViewProps = Omit<VP, 'pointerEvents'>;
17
+
18
+ type ValidAttributeTypes<Props> = Record<keyof Omit<Required<Props>, keyof ViewProps>, true> & {
19
+ accessibilityLabel: true;
20
+ };
21
+
22
+ // Taken from react-native/Libraries/Utilities/codegenNativeComponent.ts with additional Kepler option
23
+ type Options<Props> = Readonly<{
24
+ interfaceOnly?: boolean;
25
+ paperComponentName?: string;
26
+ paperComponentNameDeprecated?: string;
27
+ excludedPlatforms?: ReadonlyArray<'iOS' | 'android'>;
28
+ // Kepler specific
29
+ validAttributes?: ValidAttributeTypes<Props>;
30
+ }>;
31
+
32
+ function registerNativeComponent<Props extends ViewProps>(
33
+ componentName: string,
34
+ options?: Options<Props>
35
+ ): HostComponent<Props> {
36
+ // @ts-ignore - Kepler should be in platforms
37
+ if (Platform.OS === 'kepler') {
38
+ register(componentName, {
39
+ uiViewClassName: componentName,
40
+ validAttributes: {
41
+ ...options?.validAttributes,
42
+ },
43
+ directEventTypes: {
44
+ topLoadStart: {
45
+ registrationName: 'onLoadStart',
46
+ },
47
+ topProgress: {
48
+ registrationName: 'onProgress',
49
+ },
50
+ topError: {
51
+ registrationName: 'onError',
52
+ },
53
+ topPartialLoad: {
54
+ registrationName: 'onPartialLoad',
55
+ },
56
+ topLoad: {
57
+ registrationName: 'onLoad',
58
+ },
59
+ topLoadEnd: {
60
+ registrationName: 'onLoadEnd',
61
+ },
62
+ },
63
+ });
64
+
65
+ return componentName as unknown as HostComponent<Props>;
66
+ }
67
+ return codegenNativeComponent<Props>(componentName);
68
+ }
69
+
70
+ export default registerNativeComponent;
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './Image';
2
+ export * from './Image.types';
3
+ export * from './ImageBackground';