@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.
- package/.eslintrc.js +2 -0
- package/CHANGELOG.md +285 -0
- package/CMakeLists.txt +91 -0
- package/LICENSE +7 -0
- package/README.kepler.md +123 -0
- package/README.md +54 -0
- package/THIRD_PARTY_NOTICES.txt +24 -0
- package/android/build.gradle +124 -0
- package/android/proguard-rules.pro +28 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/java/expo/modules/image/Exceptions.kt +9 -0
- package/android/src/main/java/expo/modules/image/ExpoImageAppGlideModule.kt +19 -0
- package/android/src/main/java/expo/modules/image/ExpoImageModule.kt +192 -0
- package/android/src/main/java/expo/modules/image/ExpoImageView.kt +220 -0
- package/android/src/main/java/expo/modules/image/ExpoImageViewWrapper.kt +652 -0
- package/android/src/main/java/expo/modules/image/GlideModel.kt +73 -0
- package/android/src/main/java/expo/modules/image/ImageUtils.kt +50 -0
- package/android/src/main/java/expo/modules/image/ImageViewWrapperTarget.kt +313 -0
- package/android/src/main/java/expo/modules/image/ResourceIdHelper.kt +47 -0
- package/android/src/main/java/expo/modules/image/ThumbnailRequestCoordinatorExtension.kt +21 -0
- package/android/src/main/java/expo/modules/image/YogaUtils.kt +20 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurHashFetcher.kt +32 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashDecoder.kt +189 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoader.kt +30 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoaderFactory.kt +14 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModule.kt +17 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64DataFetcher.kt +27 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoader.kt +24 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoaderFactory.kt +12 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64Module.kt +16 -0
- package/android/src/main/java/expo/modules/image/drawing/OutlineProvider.kt +201 -0
- package/android/src/main/java/expo/modules/image/enums/ContentFit.kt +89 -0
- package/android/src/main/java/expo/modules/image/enums/ImageCacheType.kt +14 -0
- package/android/src/main/java/expo/modules/image/enums/Priority.kt +15 -0
- package/android/src/main/java/expo/modules/image/events/GlideRequestListener.kt +64 -0
- package/android/src/main/java/expo/modules/image/events/OkHttpProgressListener.kt +26 -0
- package/android/src/main/java/expo/modules/image/okhttp/ExpoImageOkHttpClientGlideModule.kt +80 -0
- package/android/src/main/java/expo/modules/image/okhttp/GlideUrlWrapperLoader.kt +55 -0
- package/android/src/main/java/expo/modules/image/records/CachePolicy.kt +10 -0
- package/android/src/main/java/expo/modules/image/records/ContentPosition.kt +89 -0
- package/android/src/main/java/expo/modules/image/records/ImageTransition.kt +8 -0
- package/android/src/main/java/expo/modules/image/records/SourceMap.kt +160 -0
- package/android/src/main/java/expo/modules/image/records/events.kt +25 -0
- package/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt +33 -0
- package/android/src/main/java/expo/modules/image/svg/SVGDrawableTranscoder.kt +37 -0
- package/android/src/main/java/expo/modules/image/svg/SVGModule.kt +26 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashDecoder.kt +365 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashFetcher.kt +31 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoader.kt +26 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoaderFactory.kt +14 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModule.kt +17 -0
- package/build/ExpoImage.d.ts +15 -0
- package/build/ExpoImage.d.ts.map +1 -0
- package/build/ExpoImage.js +75 -0
- package/build/ExpoImage.js.map +1 -0
- package/build/ExpoImage.kepler.d.ts +23 -0
- package/build/ExpoImage.kepler.d.ts.map +1 -0
- package/build/ExpoImage.kepler.js +71 -0
- package/build/ExpoImage.kepler.js.map +1 -0
- package/build/ExpoImage.web.d.ts +9 -0
- package/build/ExpoImage.web.d.ts.map +1 -0
- package/build/ExpoImage.web.js +90 -0
- package/build/ExpoImage.web.js.map +1 -0
- package/build/ExpoImageModules.d.ts +3 -0
- package/build/ExpoImageModules.d.ts.map +1 -0
- package/build/ExpoImageModules.js +4 -0
- package/build/ExpoImageModules.js.map +1 -0
- package/build/ExpoImageModules.kepler.d.ts +6 -0
- package/build/ExpoImageModules.kepler.d.ts.map +1 -0
- package/build/ExpoImageModules.kepler.js +5 -0
- package/build/ExpoImageModules.kepler.js.map +1 -0
- package/build/Image.d.ts +30 -0
- package/build/Image.d.ts.map +1 -0
- package/build/Image.js +49 -0
- package/build/Image.js.map +1 -0
- package/build/Image.types.d.ts +374 -0
- package/build/Image.types.d.ts.map +1 -0
- package/build/Image.types.js +2 -0
- package/build/Image.types.js.map +1 -0
- package/build/ImageBackground.d.ts +6 -0
- package/build/ImageBackground.d.ts.map +1 -0
- package/build/ImageBackground.js +13 -0
- package/build/ImageBackground.js.map +1 -0
- package/build/ImageViewNativeComponent.d.ts +20 -0
- package/build/ImageViewNativeComponent.d.ts.map +1 -0
- package/build/ImageViewNativeComponent.js +42 -0
- package/build/ImageViewNativeComponent.js.map +1 -0
- package/build/NativeImageLoaderKepler.d.ts +18 -0
- package/build/NativeImageLoaderKepler.d.ts.map +1 -0
- package/build/NativeImageLoaderKepler.js +3 -0
- package/build/NativeImageLoaderKepler.js.map +1 -0
- package/build/fabric/registerNativeComponent.d.ts +15 -0
- package/build/fabric/registerNativeComponent.d.ts.map +1 -0
- package/build/fabric/registerNativeComponent.js +47 -0
- package/build/fabric/registerNativeComponent.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/utils/AssetSourceResolver.web.d.ts +24 -0
- package/build/utils/AssetSourceResolver.web.d.ts.map +1 -0
- package/build/utils/AssetSourceResolver.web.js +67 -0
- package/build/utils/AssetSourceResolver.web.js.map +1 -0
- package/build/utils/blurhash/base83.d.ts +3 -0
- package/build/utils/blurhash/base83.d.ts.map +1 -0
- package/build/utils/blurhash/base83.js +103 -0
- package/build/utils/blurhash/base83.js.map +1 -0
- package/build/utils/blurhash/decode.d.ts +7 -0
- package/build/utils/blurhash/decode.d.ts.map +1 -0
- package/build/utils/blurhash/decode.js +92 -0
- package/build/utils/blurhash/decode.js.map +1 -0
- package/build/utils/blurhash/error.d.ts +4 -0
- package/build/utils/blurhash/error.d.ts.map +1 -0
- package/build/utils/blurhash/error.js +8 -0
- package/build/utils/blurhash/error.js.map +1 -0
- package/build/utils/blurhash/useBlurhash.d.ts +8 -0
- package/build/utils/blurhash/useBlurhash.d.ts.map +1 -0
- package/build/utils/blurhash/useBlurhash.js +64 -0
- package/build/utils/blurhash/useBlurhash.js.map +1 -0
- package/build/utils/blurhash/utils.d.ts +5 -0
- package/build/utils/blurhash/utils.d.ts.map +1 -0
- package/build/utils/blurhash/utils.js +21 -0
- package/build/utils/blurhash/utils.js.map +1 -0
- package/build/utils/resolveAssetSource.d.ts +3 -0
- package/build/utils/resolveAssetSource.d.ts.map +1 -0
- package/build/utils/resolveAssetSource.js +3 -0
- package/build/utils/resolveAssetSource.js.map +1 -0
- package/build/utils/resolveAssetSource.web.d.ts +9 -0
- package/build/utils/resolveAssetSource.web.d.ts.map +1 -0
- package/build/utils/resolveAssetSource.web.js +31 -0
- package/build/utils/resolveAssetSource.web.js.map +1 -0
- package/build/utils/resolveHashString.d.ts +14 -0
- package/build/utils/resolveHashString.d.ts.map +1 -0
- package/build/utils/resolveHashString.js +31 -0
- package/build/utils/resolveHashString.js.map +1 -0
- package/build/utils/resolveHashString.web.d.ts +20 -0
- package/build/utils/resolveHashString.web.d.ts.map +1 -0
- package/build/utils/resolveHashString.web.js +31 -0
- package/build/utils/resolveHashString.web.js.map +1 -0
- package/build/utils/resolveSources.d.ts +8 -0
- package/build/utils/resolveSources.d.ts.map +1 -0
- package/build/utils/resolveSources.js +45 -0
- package/build/utils/resolveSources.js.map +1 -0
- package/build/utils/thumbhash/thumbhash.d.ts +66 -0
- package/build/utils/thumbhash/thumbhash.d.ts.map +1 -0
- package/build/utils/thumbhash/thumbhash.js +338 -0
- package/build/utils/thumbhash/thumbhash.js.map +1 -0
- package/build/utils.d.ts +17 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +85 -0
- package/build/utils.js.map +1 -0
- package/build/web/AnimationManager.d.ts +37 -0
- package/build/web/AnimationManager.d.ts.map +1 -0
- package/build/web/AnimationManager.js +155 -0
- package/build/web/AnimationManager.js.map +1 -0
- package/build/web/ColorTintFilter.d.ts +12 -0
- package/build/web/ColorTintFilter.d.ts.map +1 -0
- package/build/web/ColorTintFilter.js +30 -0
- package/build/web/ColorTintFilter.js.map +1 -0
- package/build/web/ImageWrapper.d.ts +5 -0
- package/build/web/ImageWrapper.d.ts.map +1 -0
- package/build/web/ImageWrapper.js +44 -0
- package/build/web/ImageWrapper.js.map +1 -0
- package/build/web/ImageWrapper.types.d.ts +29 -0
- package/build/web/ImageWrapper.types.d.ts.map +1 -0
- package/build/web/ImageWrapper.types.js +2 -0
- package/build/web/ImageWrapper.types.js.map +1 -0
- package/build/web/getImageWrapperEventHandler.d.ts +8 -0
- package/build/web/getImageWrapperEventHandler.d.ts.map +1 -0
- package/build/web/getImageWrapperEventHandler.js +25 -0
- package/build/web/getImageWrapperEventHandler.js.map +1 -0
- package/build/web/hooks.d.ts +13 -0
- package/build/web/hooks.d.ts.map +1 -0
- package/build/web/hooks.js +58 -0
- package/build/web/hooks.js.map +1 -0
- package/build/web/imageStyles.d.ts +2 -0
- package/build/web/imageStyles.d.ts.map +1 -0
- package/build/web/imageStyles.js +137 -0
- package/build/web/imageStyles.js.map +1 -0
- package/build/web/positioning.d.ts +11 -0
- package/build/web/positioning.d.ts.map +1 -0
- package/build/web/positioning.js +35 -0
- package/build/web/positioning.js.map +1 -0
- package/build/web/useSourceSelection.d.ts +14 -0
- package/build/web/useSourceSelection.d.ts.map +1 -0
- package/build/web/useSourceSelection.js +98 -0
- package/build/web/useSourceSelection.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/Blurhash.swift +326 -0
- package/ios/BlurhashLoader.swift +52 -0
- package/ios/ContentFit.swift +55 -0
- package/ios/ContentPosition.swift +108 -0
- package/ios/ExpoImage.podspec +30 -0
- package/ios/ImageCachePolicy.swift +24 -0
- package/ios/ImageCacheType.swift +21 -0
- package/ios/ImageModule.swift +127 -0
- package/ios/ImagePriority.swift +22 -0
- package/ios/ImageSource.swift +44 -0
- package/ios/ImageTransition.swift +67 -0
- package/ios/ImageUtils.swift +227 -0
- package/ios/ImageView.swift +469 -0
- package/ios/Loaders/PhotoLibraryAssetLoader.swift +146 -0
- package/ios/Thumbhash.swift +550 -0
- package/ios/ThumbhashLoader.swift +53 -0
- package/jest.config.js +3 -0
- package/kepler/ExpoImage.cpp +63 -0
- package/kepler/ExpoImage.h +29 -0
- package/kepler/ExpoImageCacheHandler.cpp +15 -0
- package/kepler/ExpoImageCacheHandler.h +28 -0
- package/kepler/ExpoImageComponent.cpp +579 -0
- package/kepler/ExpoImageComponent.h +199 -0
- package/kepler/ImageWrapper/BlurhashImageWrapper.cpp +37 -0
- package/kepler/ImageWrapper/BlurhashImageWrapper.h +23 -0
- package/kepler/ImageWrapper/CacheImageWrapper.cpp +80 -0
- package/kepler/ImageWrapper/CacheImageWrapper.h +41 -0
- package/kepler/ImageWrapper/HashImageWrapper.cpp +21 -0
- package/kepler/ImageWrapper/HashImageWrapper.h +22 -0
- package/kepler/ImageWrapper/ImageWrapper.cpp +24 -0
- package/kepler/ImageWrapper/ImageWrapper.h +33 -0
- package/kepler/ImageWrapper/LocalImageWrapper.cpp +61 -0
- package/kepler/ImageWrapper/LocalImageWrapper.h +30 -0
- package/kepler/ImageWrapper/ThumbhashImageWrapper.cpp +33 -0
- package/kepler/ImageWrapper/ThumbhashImageWrapper.h +20 -0
- package/kepler/KeplerImageViewComponent.h +64 -0
- package/kepler/KeplerInit.cpp +35 -0
- package/kepler/blurhash/common.h +32 -0
- package/kepler/blurhash/decode.cpp +187 -0
- package/kepler/blurhash/decode.h +58 -0
- package/kepler/contentposition/ImageContentPosition.cpp +86 -0
- package/kepler/contentposition/ImageContentPosition.h +48 -0
- package/kepler/enums/ImageContentFit.h +17 -0
- package/kepler/enums/ImagePriority.h +17 -0
- package/kepler/managers/ExpoImageManager.cpp +38 -0
- package/kepler/managers/ExpoImageManager.h +23 -0
- package/kepler/test/ExpoImage.cpp +73 -0
- package/kepler/test/ExpoImageComponent.cpp +290 -0
- package/kepler/test/blurhash/decode.cpp +39 -0
- package/kepler/test/contentposition/ImageContentPosition.cpp +100 -0
- package/kepler/test/managers/ExpoImageManager.cpp +39 -0
- package/kepler/test/thumbhash/decode.cpp +18 -0
- package/kepler/test/utils/LoaderDelegate.cpp +130 -0
- package/kepler/thumbhash/decode.cpp +166 -0
- package/kepler/thumbhash/decode.h +22 -0
- package/kepler/utils/PlaceholderImageLoaderDelegate.cpp +26 -0
- package/kepler/utils/PlaceholderImageLoaderDelegate.h +26 -0
- package/kepler/utils/PrefetchImageLoaderDelegate.cpp +55 -0
- package/kepler/utils/PrefetchImageLoaderDelegate.h +35 -0
- package/kepler/utils/SourceImageLoaderDelegate.cpp +47 -0
- package/kepler/utils/SourceImageLoaderDelegate.h +42 -0
- package/kepler/utils/SourceImageLoaderDelegateEmitter.cpp +15 -0
- package/kepler/utils/SourceImageLoaderDelegateEmitter.h +28 -0
- package/kepler-compatibility.json +8 -0
- package/package.json +1 -0
- package/react-native.config.js +22 -0
- package/src/ExpoImage.kepler.tsx +119 -0
- package/src/ExpoImage.tsx +119 -0
- package/src/ExpoImage.web.tsx +155 -0
- package/src/ExpoImageModules.kepler.ts +7 -0
- package/src/ExpoImageModules.ts +4 -0
- package/src/Image.tsx +82 -0
- package/src/Image.types.ts +450 -0
- package/src/ImageBackground.tsx +18 -0
- package/src/ImageViewNativeComponent.ts +59 -0
- package/src/NativeImageLoaderKepler.ts +22 -0
- package/src/fabric/registerNativeComponent.ts +70 -0
- package/src/index.ts +3 -0
- package/src/utils/AssetSourceResolver.web.ts +88 -0
- package/src/utils/blurhash/base83.ts +104 -0
- package/src/utils/blurhash/decode.ts +114 -0
- package/src/utils/blurhash/error.ts +7 -0
- package/src/utils/blurhash/useBlurhash.tsx +81 -0
- package/src/utils/blurhash/utils.ts +21 -0
- package/src/utils/resolveAssetSource.tsx +3 -0
- package/src/utils/resolveAssetSource.web.ts +40 -0
- package/src/utils/resolveHashString.tsx +36 -0
- package/src/utils/resolveHashString.web.tsx +33 -0
- package/src/utils/resolveSources.tsx +48 -0
- package/src/utils/thumbhash/thumbhash.ts +387 -0
- package/src/utils.ts +109 -0
- package/src/web/AnimationManager.tsx +224 -0
- package/src/web/ColorTintFilter.tsx +36 -0
- package/src/web/ImageWrapper.tsx +85 -0
- package/src/web/ImageWrapper.types.ts +36 -0
- package/src/web/getImageWrapperEventHandler.ts +29 -0
- package/src/web/hooks.ts +72 -0
- package/src/web/imageStyles.tsx +136 -0
- package/src/web/positioning.ts +48 -0
- package/src/web/useSourceSelection.ts +151 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
#include <KeplerScript/utils/image/KeplerScriptImageCacheHandler.h>
|
|
11
|
+
#include <Volta/animation/Animated.h>
|
|
12
|
+
#include <Volta/animation/Animation.h>
|
|
13
|
+
#include <Volta/animation/Animator.h>
|
|
14
|
+
#include <Volta/animation/Driver.h>
|
|
15
|
+
#include <Volta/animation/Transform.h>
|
|
16
|
+
#include <Volta/ui/presentation/EventController.h>
|
|
17
|
+
#include <Volta/utils/Image.h>
|
|
18
|
+
#include <graphics/ClipRRectLayer.h>
|
|
19
|
+
#include <graphics/ImageFilterLayer.h>
|
|
20
|
+
|
|
21
|
+
#include "ImageWrapper/ImageWrapper.h"
|
|
22
|
+
#include "KeplerImageViewComponent.h"
|
|
23
|
+
#include "KeplerScript/utils/KeplerUIManager.h"
|
|
24
|
+
#include "contentposition/ImageContentPosition.h"
|
|
25
|
+
#include "enums/ImageContentFit.h"
|
|
26
|
+
#include "enums/ImagePriority.h"
|
|
27
|
+
#include "react/renderer/components/image/ImageShadowNode.h"
|
|
28
|
+
|
|
29
|
+
struct ImageTransition {
|
|
30
|
+
float duration;
|
|
31
|
+
std::string timing;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class ExpoImageDrawableLayer : public volta::graphics::DrawableLayer {
|
|
35
|
+
public:
|
|
36
|
+
ExpoImageDrawableLayer();
|
|
37
|
+
void onDraw(volta::graphics::Canvas& canvas) override;
|
|
38
|
+
void setSize(const volta::graphics::Size&);
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
#ifdef UNIT_TEST
|
|
42
|
+
public:
|
|
43
|
+
#endif
|
|
44
|
+
/**
|
|
45
|
+
* KeplerImageViewComponent is marked as friend class to access all private members
|
|
46
|
+
* instead of exposing individual setters. The members will be set when the props are modified
|
|
47
|
+
*/
|
|
48
|
+
friend class ExpoImageComponent;
|
|
49
|
+
volta::react::BorderCalculatedMetrics borderCalculatedMetrics_;
|
|
50
|
+
volta::graphics::Size size_;
|
|
51
|
+
std::shared_ptr<ImageWrapper> imageWrapper_;
|
|
52
|
+
std::shared_ptr<ImageWrapper> oldImageWrapper_;
|
|
53
|
+
std::shared_ptr<ImageWrapper> placeholderWrapper_;
|
|
54
|
+
ImageContentFit imageContentFit_;
|
|
55
|
+
ImageContentFit imagePlaceholderContentFit_;
|
|
56
|
+
bool imageAllowDownscaling_;
|
|
57
|
+
ImageContentPosition imageContentPosition_;
|
|
58
|
+
volta::graphics::Color overlayColor_;
|
|
59
|
+
volta::graphics::Color tintColor_;
|
|
60
|
+
double blurRadius_ = 0.0;
|
|
61
|
+
uint8_t opacity_ = 255;
|
|
62
|
+
std::function<void()> onAnimationInit_;
|
|
63
|
+
bool shouldInitializeAnimation_{false};
|
|
64
|
+
|
|
65
|
+
void paintImageWithContentFit(
|
|
66
|
+
const volta::graphics::Image& image,
|
|
67
|
+
volta::graphics::Canvas& canvas,
|
|
68
|
+
const volta::graphics::Paint& paint,
|
|
69
|
+
ImageContentFit imageContentFit,
|
|
70
|
+
bool isPlaceholderUsed);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
class ExpoImageComponent final : public volta::react::KeplerViewComponent {
|
|
74
|
+
public:
|
|
75
|
+
ExpoImageComponent(const std::shared_ptr<volta::react::KeplerScriptImageCacheHandler>&);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @brief Set the overlay color
|
|
79
|
+
* @details When the image has rounded corners, specifying an overlayColor will cause the
|
|
80
|
+
* remaining space in the corners to be filled with a solid color.
|
|
81
|
+
* @param newValue
|
|
82
|
+
*/
|
|
83
|
+
void setOverlayColor(const int& newValue);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @brief Set the tint color
|
|
87
|
+
* @details Changes the color of all the non-transparent pixels to the tintColor.
|
|
88
|
+
* @param newValue
|
|
89
|
+
*/
|
|
90
|
+
void setTintColor(const int& newValue);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @brief Set the Blur Radius
|
|
94
|
+
* @details Changes the pixels for the Image.
|
|
95
|
+
* @param newValue
|
|
96
|
+
*/
|
|
97
|
+
void setBlurRadius(const double& newValue);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @brief Set the content fit ('cover', 'contain', 'fill', 'none', 'scale-down')
|
|
101
|
+
* @param newValue
|
|
102
|
+
*/
|
|
103
|
+
void setContentFit(const std::string& newValue);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @brief Set the placeholder content fit ('cover', 'contain', 'fill', 'none', 'scale-down')
|
|
107
|
+
* @param newValue
|
|
108
|
+
*/
|
|
109
|
+
void setPlaceholderContentFit(const std::string& newValue);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @brief Set the allow downscaling prop (true/false)
|
|
113
|
+
* @param newValue
|
|
114
|
+
*/
|
|
115
|
+
void setAllowDownscaling(const bool& newValue);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @brief Set the local default image source uri
|
|
119
|
+
* @param newValue JsonContainer with ImageSource data
|
|
120
|
+
*/
|
|
121
|
+
void setPlaceholder(const utils::json::JsonContainer& newValue);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @brief Set the local default image source uri
|
|
125
|
+
* @param newValue JsonContainer with ImageSource data
|
|
126
|
+
*/
|
|
127
|
+
void setSource(const utils::json::JsonContainer& newValue);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @brief Set the priority for completing image load ('low', 'normal', 'high').
|
|
131
|
+
* @param newValue
|
|
132
|
+
*/
|
|
133
|
+
void setPriority(const std::string& newValue);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @brief Set the content position
|
|
137
|
+
* @param newValue JsonContainer with ImageContentPosition data
|
|
138
|
+
*/
|
|
139
|
+
void setContentPosition(const utils::json::JsonContainer& newValue);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @brief Set the image transition
|
|
143
|
+
* @param newValue JsonContainer with ImageTransition data
|
|
144
|
+
*/
|
|
145
|
+
void setTransition(const utils::json::JsonContainer& newValue);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @brief Set the recycling key
|
|
149
|
+
* @param newValue
|
|
150
|
+
*/
|
|
151
|
+
void setRecyclingKey(const std::string& newValue);
|
|
152
|
+
|
|
153
|
+
// void buildAccessibilityInfo(AccessibilityContext& accessibilityContext) override;
|
|
154
|
+
|
|
155
|
+
virtual void event(volta::EventContext&) override;
|
|
156
|
+
|
|
157
|
+
void init();
|
|
158
|
+
|
|
159
|
+
protected:
|
|
160
|
+
void updateLayoutMetrics(
|
|
161
|
+
const std::shared_ptr<volta::react::KeplerViewComponentLayoutMetrics>& oldLayoutMetrics,
|
|
162
|
+
const std::shared_ptr<volta::react::KeplerViewComponentLayoutMetrics>& newLayoutMetrics) override;
|
|
163
|
+
|
|
164
|
+
void updateState(const std::shared_ptr<const void>& oldState, const std::shared_ptr<const void>& newState) override;
|
|
165
|
+
|
|
166
|
+
private:
|
|
167
|
+
#ifdef UNIT_TEST
|
|
168
|
+
public:
|
|
169
|
+
#endif
|
|
170
|
+
mutable ExpoImageDrawableLayer imageDrawableLayer_;
|
|
171
|
+
volta::graphics::Color overlayColor_;
|
|
172
|
+
volta::graphics::Color tintColor_;
|
|
173
|
+
std::string contentFit_;
|
|
174
|
+
std::string placeholderContentFit_;
|
|
175
|
+
std::string recyclingKey_;
|
|
176
|
+
bool shouldClearOnSourceChange_ = false;
|
|
177
|
+
std::vector<facebook::react::ImageSource> sources_;
|
|
178
|
+
std::vector<facebook::react::ImageSource> placeholders_;
|
|
179
|
+
std::shared_ptr<ImageWrapper> currentSource_;
|
|
180
|
+
std::shared_ptr<ImageWrapper> oldSource_;
|
|
181
|
+
std::shared_ptr<ImageWrapper> currentPlaceholder_;
|
|
182
|
+
std::shared_ptr<volta::react::KeplerScriptImageCacheHandler> cacheHandler_;
|
|
183
|
+
ImagePriority priority_;
|
|
184
|
+
volta::Animator animator_;
|
|
185
|
+
volta::Animation<float> animation_;
|
|
186
|
+
bool shouldAnimateOnSrcChange_{false};
|
|
187
|
+
ImageTransition imageTransition;
|
|
188
|
+
const float opacityTargetValue_{255.0f};
|
|
189
|
+
|
|
190
|
+
std::optional<facebook::react::ImageSource> getBestSource(const std::vector<facebook::react::ImageSource>&);
|
|
191
|
+
std::shared_ptr<volta::IImageLoaderDelegate> createSourceLoaderDelegate(std::function<void()> onLoad);
|
|
192
|
+
std::shared_ptr<volta::IImageLoaderDelegate> createPlaceholderLoaderDelegate(std::function<void()> onLoad);
|
|
193
|
+
void createCurrentSource(facebook::react::ImageSource);
|
|
194
|
+
void rerenderIfNeeded();
|
|
195
|
+
void loadLocalImage(const utils::json::JsonContainer& imageSourceJsonContainer);
|
|
196
|
+
void startImageAnimation();
|
|
197
|
+
void animateImage();
|
|
198
|
+
void createImageAnimation(ImageTransition& imageTransition);
|
|
199
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
#include "BlurhashImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
#include <boost/algorithm/string.hpp>
|
|
12
|
+
|
|
13
|
+
#include "blurhash/decode.h"
|
|
14
|
+
|
|
15
|
+
BlurHashImageWrapper::BlurHashImageWrapper(
|
|
16
|
+
const facebook::react::ImageSource& source,
|
|
17
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate) :
|
|
18
|
+
HashImageWrapper(source, loaderDelegate){};
|
|
19
|
+
|
|
20
|
+
void BlurHashImageWrapper::load() {
|
|
21
|
+
loaderDelegate_->notifyImageLoadStart();
|
|
22
|
+
auto delimiter_pos = source_.uri.find("/");
|
|
23
|
+
if (delimiter_pos == std::string::npos) return;
|
|
24
|
+
|
|
25
|
+
auto uri = source_.uri.substr(delimiter_pos + 1);
|
|
26
|
+
const int channels = 4;
|
|
27
|
+
const int width = source_.size.width;
|
|
28
|
+
const int height = source_.size.height;
|
|
29
|
+
|
|
30
|
+
auto pixels = decodeBlurhash(uri.c_str(), width, height, 1, channels);
|
|
31
|
+
imagePtr_ = volta::graphics::Image::makeRasterImage(
|
|
32
|
+
volta::graphics::Size(width, height),
|
|
33
|
+
std::move(pixels),
|
|
34
|
+
width * channels);
|
|
35
|
+
isLoaded_ = true;
|
|
36
|
+
loaderDelegate_->notifyImageLoadSuccess(*imagePtr_.get());
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "HashImageWrapper.h"
|
|
12
|
+
|
|
13
|
+
class BlurHashImageWrapper : public HashImageWrapper {
|
|
14
|
+
public:
|
|
15
|
+
BlurHashImageWrapper(
|
|
16
|
+
const facebook::react::ImageSource& source,
|
|
17
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate);
|
|
18
|
+
|
|
19
|
+
void load();
|
|
20
|
+
|
|
21
|
+
private:
|
|
22
|
+
volta::graphics::Size size_;
|
|
23
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
#include "CacheImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/components/ImageSourceBuilder.h>
|
|
12
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
13
|
+
|
|
14
|
+
#include "KeplerScript/utils/KeplerUIManager.h"
|
|
15
|
+
|
|
16
|
+
CacheImageWrapper::CacheImageWrapper(
|
|
17
|
+
const facebook::react::ImageSource& source,
|
|
18
|
+
const std::shared_ptr<volta::react::KeplerScriptImageCacheHandler>& cacheHandler,
|
|
19
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate,
|
|
20
|
+
const ImagePriority priority) :
|
|
21
|
+
ImageWrapper(source, loaderDelegate),
|
|
22
|
+
cacheHandler_(cacheHandler),
|
|
23
|
+
priority_(priority) {}
|
|
24
|
+
|
|
25
|
+
void CacheImageWrapper::load() {
|
|
26
|
+
if (isLoading_) return;
|
|
27
|
+
|
|
28
|
+
if (!cacheHandler_) {
|
|
29
|
+
volta::react::KPLog.warn("{} :: Invalid KeplerScriptImageCacheHandler", __func__);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
volta::ImageOptions imageOptions;
|
|
34
|
+
if (source_.resizeMode != facebook::react::ImageResizeMode::Center &&
|
|
35
|
+
source_.resizeMode != facebook::react::ImageResizeMode::Repeat) {
|
|
36
|
+
// facebook::react::ImageResizeMode::Center and facebook::react::ImageResizeMode::Repeat requires that the
|
|
37
|
+
// image should not be subjected to a canvas based resize and has its original size intact. This checks
|
|
38
|
+
// ensures that the canvas resize occurs for only image fit configurations other than Center and Repeat.
|
|
39
|
+
imageOptions.preferredSize(volta::graphics::Size{source_.size.width, source_.size.height});
|
|
40
|
+
imageOptions.keepAspectRatio(true);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const volta::ImageSource imageSourceUrl = volta::react::buildImageSource(source_.uri);
|
|
44
|
+
volta::ImageDetails details(imageSourceUrl, imageOptions, static_cast<uint8_t>(priority_));
|
|
45
|
+
cacheHandler_->load(details, shared_from_this());
|
|
46
|
+
isLoading_ = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
volta::graphics::Image* CacheImageWrapper::getImage() {
|
|
50
|
+
if (imageRef_ != nullptr) {
|
|
51
|
+
return imageRef_->getImage();
|
|
52
|
+
}
|
|
53
|
+
return nullptr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void CacheImageWrapper::notifyImageLoadStart() {
|
|
57
|
+
loaderDelegate_->notifyImageLoadStart();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
void CacheImageWrapper::notifyImageLoadProgress(float progress) {
|
|
61
|
+
loaderDelegate_->notifyImageLoadProgress(progress);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
void CacheImageWrapper::notifyImageLoadSuccess(volta::graphics::Image) {
|
|
65
|
+
/* migrated to notifyImageLoadSuccess(volta::image::ImageRef) below */
|
|
66
|
+
volta::react::KPLog.warn(
|
|
67
|
+
"ExpoImage :: Deprecated CacheImageWrapper::notifyImageLoadSuccess(volta::graphics::Image) called");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void CacheImageWrapper::notifyImageLoadSuccess(volta::image::ImageRef imageRef) {
|
|
71
|
+
isLoaded_ = true;
|
|
72
|
+
imageRef_ = std::make_shared<volta::image::ImageRef>(std::move(imageRef));
|
|
73
|
+
loaderDelegate_->notifyImageLoadSuccess(imageRef);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void CacheImageWrapper::notifyImageLoadFailure(volta::ImageLoadError error) {
|
|
77
|
+
isLoaded_ = false;
|
|
78
|
+
imageRef_ = nullptr;
|
|
79
|
+
loaderDelegate_->notifyImageLoadFailure(error);
|
|
80
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
#include <KeplerScript/utils/image/KeplerScriptImageCacheHandler.h>
|
|
11
|
+
|
|
12
|
+
#include "ImageWrapper.h"
|
|
13
|
+
#include <KeplerScript/utils/image/LocalAssetImageLoader.h>
|
|
14
|
+
#include "enums/ImagePriority.h"
|
|
15
|
+
|
|
16
|
+
class CacheImageWrapper
|
|
17
|
+
: public ImageWrapper
|
|
18
|
+
, public volta::IImageLoaderDelegate
|
|
19
|
+
, public std::enable_shared_from_this<CacheImageWrapper> {
|
|
20
|
+
public:
|
|
21
|
+
CacheImageWrapper(
|
|
22
|
+
const facebook::react::ImageSource& source,
|
|
23
|
+
const std::shared_ptr<volta::react::KeplerScriptImageCacheHandler>& cacheHandler,
|
|
24
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate,
|
|
25
|
+
const ImagePriority priority);
|
|
26
|
+
|
|
27
|
+
void load();
|
|
28
|
+
volta::graphics::Image* getImage();
|
|
29
|
+
|
|
30
|
+
void notifyImageLoadStart() override;
|
|
31
|
+
void notifyImageLoadProgress(float progress) override;
|
|
32
|
+
void notifyImageLoadSuccess(volta::graphics::Image) override;
|
|
33
|
+
void notifyImageLoadSuccess(volta::image::ImageRef imageRef) override;
|
|
34
|
+
void notifyImageLoadFailure(volta::ImageLoadError error) override;
|
|
35
|
+
|
|
36
|
+
private:
|
|
37
|
+
std::shared_ptr<volta::image::ImageRef> imageRef_;
|
|
38
|
+
std::shared_ptr<volta::react::KeplerScriptImageCacheHandler> cacheHandler_;
|
|
39
|
+
bool isLoading_ = false;
|
|
40
|
+
ImagePriority priority_;
|
|
41
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
#include "HashImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
HashImageWrapper::HashImageWrapper(
|
|
12
|
+
const facebook::react::ImageSource& source,
|
|
13
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate) :
|
|
14
|
+
ImageWrapper(source, loaderDelegate){};
|
|
15
|
+
|
|
16
|
+
volta::graphics::Image* HashImageWrapper::getImage() {
|
|
17
|
+
if (imagePtr_ != nullptr) {
|
|
18
|
+
return imagePtr_.get();
|
|
19
|
+
}
|
|
20
|
+
return nullptr;
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "ImageWrapper.h"
|
|
12
|
+
|
|
13
|
+
class HashImageWrapper : public ImageWrapper {
|
|
14
|
+
public:
|
|
15
|
+
HashImageWrapper(
|
|
16
|
+
const facebook::react::ImageSource& source,
|
|
17
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate);
|
|
18
|
+
volta::graphics::Image* getImage();
|
|
19
|
+
|
|
20
|
+
protected:
|
|
21
|
+
std::unique_ptr<volta::graphics::Image> imagePtr_;
|
|
22
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
#include "ImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
ImageWrapper::ImageWrapper(
|
|
12
|
+
const facebook::react::ImageSource& source,
|
|
13
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate) :
|
|
14
|
+
source_(source),
|
|
15
|
+
isLoaded_(false),
|
|
16
|
+
loaderDelegate_(loaderDelegate){};
|
|
17
|
+
|
|
18
|
+
bool ImageWrapper::isLoaded() {
|
|
19
|
+
return isLoaded_;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const facebook::react::ImageSource& ImageWrapper::getSource() const {
|
|
23
|
+
return source_;
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
6
|
+
*
|
|
7
|
+
* Use is subject to license terms.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <Volta/utils/Image.h>
|
|
13
|
+
|
|
14
|
+
#ifndef KEPLER
|
|
15
|
+
#define KEPLER
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#include "react/renderer/components/image/ImageShadowNode.h"
|
|
19
|
+
|
|
20
|
+
class ImageWrapper {
|
|
21
|
+
public:
|
|
22
|
+
ImageWrapper(const facebook::react::ImageSource& source, const volta::IImageLoaderDelegate::Shared& loaderDelegate);
|
|
23
|
+
virtual ~ImageWrapper() = default;
|
|
24
|
+
virtual void load() = 0;
|
|
25
|
+
virtual bool isLoaded();
|
|
26
|
+
virtual volta::graphics::Image* getImage() = 0;
|
|
27
|
+
const facebook::react::ImageSource& getSource() const;
|
|
28
|
+
|
|
29
|
+
protected:
|
|
30
|
+
bool isLoaded_;
|
|
31
|
+
facebook::react::ImageSource source_;
|
|
32
|
+
const volta::IImageLoaderDelegate::Shared loaderDelegate_;
|
|
33
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
#include "LocalImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
12
|
+
|
|
13
|
+
#include "KeplerScript/utils/KeplerUIManager.h"
|
|
14
|
+
|
|
15
|
+
LocalImageWrapper::LocalImageWrapper(
|
|
16
|
+
const facebook::react::ImageSource& source,
|
|
17
|
+
const std::weak_ptr<volta::react::LocalAssetImageLoader>& localImageLoader,
|
|
18
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate) :
|
|
19
|
+
ImageWrapper(source, loaderDelegate),
|
|
20
|
+
localImageLoader_(localImageLoader) {}
|
|
21
|
+
|
|
22
|
+
void LocalImageWrapper::load() {
|
|
23
|
+
if (isLoading_) return;
|
|
24
|
+
auto localAssetImageLoader = localImageLoader_.lock();
|
|
25
|
+
if (!localAssetImageLoader) {
|
|
26
|
+
volta::react::KPLog.warn("{} :: Invalid local asset image loader", __func__);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
loaderDelegate_->notifyImageLoadStart();
|
|
31
|
+
volta::ImageOptions imageOptions;
|
|
32
|
+
if (source_.resizeMode != facebook::react::ImageResizeMode::Center &&
|
|
33
|
+
source_.resizeMode != facebook::react::ImageResizeMode::Repeat) {
|
|
34
|
+
// facebook::react::ImageResizeMode::Center and facebook::react::ImageResizeMode::Repeat requires that the
|
|
35
|
+
// image should not be subjected to a canvas based resize and has its original size intact. This checks
|
|
36
|
+
// ensures that the canvas resize occurs for only image fit configurations other than Center and Repeat.
|
|
37
|
+
imageOptions.preferredSize(volta::graphics::Size{source_.size.width, source_.size.height});
|
|
38
|
+
imageOptions.keepAspectRatio(true);
|
|
39
|
+
}
|
|
40
|
+
isLoading_ = true;
|
|
41
|
+
localAssetImageLoader->loadImage(
|
|
42
|
+
source_.uri,
|
|
43
|
+
imageOptions,
|
|
44
|
+
[weakSelf = weak_from_this()](std::shared_ptr<volta::image::ImageRef> imageRefPtr) {
|
|
45
|
+
volta::react::KeplerUIManager::getInstance().executeOnUIThread([weakSelf, imageRefPtr]() {
|
|
46
|
+
if (auto self = weakSelf.lock()) {
|
|
47
|
+
self->imageRef_ = imageRefPtr;
|
|
48
|
+
self->isLoaded_ = true;
|
|
49
|
+
self->loaderDelegate_->notifyImageLoadSuccess(*imageRefPtr.get());
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
volta::graphics::Image* LocalImageWrapper::getImage() {
|
|
57
|
+
if (imageRef_ != nullptr) {
|
|
58
|
+
return imageRef_->getImage();
|
|
59
|
+
}
|
|
60
|
+
return nullptr;
|
|
61
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "ImageWrapper.h"
|
|
12
|
+
#include <KeplerScript/utils/image/LocalAssetImageLoader.h>
|
|
13
|
+
|
|
14
|
+
class LocalImageWrapper
|
|
15
|
+
: public ImageWrapper
|
|
16
|
+
, public std::enable_shared_from_this<LocalImageWrapper> {
|
|
17
|
+
public:
|
|
18
|
+
LocalImageWrapper(
|
|
19
|
+
const facebook::react::ImageSource& source,
|
|
20
|
+
const std::weak_ptr<volta::react::LocalAssetImageLoader>& localImageLoader,
|
|
21
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate);
|
|
22
|
+
|
|
23
|
+
void load();
|
|
24
|
+
volta::graphics::Image* getImage();
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
std::shared_ptr<volta::image::ImageRef> imageRef_;
|
|
28
|
+
std::weak_ptr<volta::react::LocalAssetImageLoader> localImageLoader_;
|
|
29
|
+
bool isLoading_ = false;
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
#include "ThumbhashImageWrapper.h"
|
|
10
|
+
|
|
11
|
+
#include "thumbhash/decode.h"
|
|
12
|
+
|
|
13
|
+
ThumbHashImageWrapper::ThumbHashImageWrapper(
|
|
14
|
+
const facebook::react::ImageSource& source,
|
|
15
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate) :
|
|
16
|
+
HashImageWrapper(source, loaderDelegate){};
|
|
17
|
+
|
|
18
|
+
void ThumbHashImageWrapper::load() {
|
|
19
|
+
loaderDelegate_->notifyImageLoadStart();
|
|
20
|
+
auto delimiter_pos = source_.uri.find("/");
|
|
21
|
+
if (delimiter_pos == std::string::npos) return;
|
|
22
|
+
|
|
23
|
+
auto uri = source_.uri.substr(delimiter_pos + 1);
|
|
24
|
+
const int channels = 4;
|
|
25
|
+
auto thumbResult = decodeThumbhash(uri);
|
|
26
|
+
|
|
27
|
+
imagePtr_ = volta::graphics::Image::makeRasterImage(
|
|
28
|
+
volta::graphics::Size(thumbResult.width, thumbResult.height),
|
|
29
|
+
std::move(thumbResult.pixelArray),
|
|
30
|
+
thumbResult.width * channels);
|
|
31
|
+
isLoaded_ = true;
|
|
32
|
+
loaderDelegate_->notifyImageLoadSuccess(*imagePtr_.get());
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "HashImageWrapper.h"
|
|
12
|
+
|
|
13
|
+
class ThumbHashImageWrapper : public HashImageWrapper {
|
|
14
|
+
public:
|
|
15
|
+
ThumbHashImageWrapper(
|
|
16
|
+
const facebook::react::ImageSource& source,
|
|
17
|
+
const volta::IImageLoaderDelegate::Shared& loaderDelegate);
|
|
18
|
+
|
|
19
|
+
void load();
|
|
20
|
+
};
|