@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,224 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ImageTransition } from '../Image.types';
|
|
4
|
+
|
|
5
|
+
type Callbacks = {
|
|
6
|
+
onReady?: (() => void) | null;
|
|
7
|
+
onAnimationFinished?: (() => void) | null;
|
|
8
|
+
onMount?: (() => void) | null;
|
|
9
|
+
onError?: (() => void) | null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AnimationManagerNode = [
|
|
13
|
+
key: string,
|
|
14
|
+
renderFunction: (
|
|
15
|
+
renderProps: NonNullable<Callbacks>
|
|
16
|
+
) => (className: string, style: React.CSSProperties) => React.ReactElement,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const SUPPORTED_ANIMATIONS: ImageTransition['effect'][] = [
|
|
20
|
+
'cross-dissolve',
|
|
21
|
+
'flip-from-left',
|
|
22
|
+
'flip-from-right',
|
|
23
|
+
'flip-from-top',
|
|
24
|
+
'flip-from-bottom',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
type NodeStatus = 'mounted' | 'in' | 'active' | 'out' | 'errored';
|
|
28
|
+
|
|
29
|
+
function useAnimationManagerNode(node: AnimationManagerNode | null, initialStatus?: NodeStatus) {
|
|
30
|
+
const newNode = React.useMemo(() => {
|
|
31
|
+
if (!node) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const [animationKey, renderFunction] = node;
|
|
35
|
+
// key, ReactElement, ref, callbacks
|
|
36
|
+
return {
|
|
37
|
+
animationKey,
|
|
38
|
+
persistedElement: renderFunction,
|
|
39
|
+
status: (initialStatus || 'mounted') as NodeStatus,
|
|
40
|
+
};
|
|
41
|
+
}, [node?.[0]]);
|
|
42
|
+
return newNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function validateTimingFunctionForAnimation(
|
|
46
|
+
animationClass: ImageTransition['effect'],
|
|
47
|
+
timingFunction: ImageTransition['timing']
|
|
48
|
+
) {
|
|
49
|
+
if (animationClass?.includes('flip')) {
|
|
50
|
+
if (timingFunction?.includes('ease')) {
|
|
51
|
+
return 'ease-in-out';
|
|
52
|
+
}
|
|
53
|
+
return 'linear';
|
|
54
|
+
}
|
|
55
|
+
return timingFunction || null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function validateAnimationClass(effect: ImageTransition['effect']) {
|
|
59
|
+
if (SUPPORTED_ANIMATIONS.includes(effect)) {
|
|
60
|
+
return effect;
|
|
61
|
+
}
|
|
62
|
+
return 'cross-dissolve';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getAnimatorFromTransition(transition: ImageTransition | null | undefined) {
|
|
66
|
+
if (!transition?.duration) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const animationClass = validateAnimationClass(transition.effect);
|
|
70
|
+
if (!animationClass) {
|
|
71
|
+
return {
|
|
72
|
+
startingClass: '',
|
|
73
|
+
animateInClass: '',
|
|
74
|
+
animateOutClass: '',
|
|
75
|
+
containerClass: '',
|
|
76
|
+
timingFunction: 'linear',
|
|
77
|
+
animationClass: '',
|
|
78
|
+
duration: 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const timingFunction = validateTimingFunctionForAnimation(animationClass, transition.timing);
|
|
83
|
+
const timingClass = `image-timing-${timingFunction}`;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
startingClass: `${animationClass}-start`,
|
|
87
|
+
animateInClass: [animationClass, 'transitioning', `${animationClass}-active`, timingClass].join(
|
|
88
|
+
' '
|
|
89
|
+
),
|
|
90
|
+
animateOutClass: [animationClass, `${animationClass}-end`, timingClass].join(' '),
|
|
91
|
+
containerClass: `${animationClass}-container`,
|
|
92
|
+
timingFunction,
|
|
93
|
+
animationClass,
|
|
94
|
+
duration: transition?.duration || 0,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type MountedAnimationNode = {
|
|
99
|
+
animationKey: string;
|
|
100
|
+
persistedElement: (
|
|
101
|
+
renderProps: Callbacks
|
|
102
|
+
) => (className: string, style: React.CSSProperties) => React.ReactElement;
|
|
103
|
+
status: NodeStatus;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default function AnimationManager({
|
|
107
|
+
children: renderFunction,
|
|
108
|
+
initial,
|
|
109
|
+
transition,
|
|
110
|
+
recyclingKey,
|
|
111
|
+
}: {
|
|
112
|
+
children: AnimationManagerNode;
|
|
113
|
+
initial: AnimationManagerNode | null;
|
|
114
|
+
transition: ImageTransition | null | undefined;
|
|
115
|
+
recyclingKey?: string | null | undefined;
|
|
116
|
+
}) {
|
|
117
|
+
const animation = getAnimatorFromTransition(transition);
|
|
118
|
+
|
|
119
|
+
const initialNode = useAnimationManagerNode(initial, 'active');
|
|
120
|
+
|
|
121
|
+
const [nodes, setNodes] = React.useState<MountedAnimationNode[]>(
|
|
122
|
+
initialNode ? [initialNode] : []
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const [prevRecyclingKey, setPrevRecyclingKey] = React.useState<string>(recyclingKey ?? '');
|
|
126
|
+
if (prevRecyclingKey !== (recyclingKey ?? '')) {
|
|
127
|
+
setPrevRecyclingKey(recyclingKey ?? '');
|
|
128
|
+
setNodes(initialNode ? [initialNode] : []);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const removeAllNodesOfKeyExceptShowing = (key?: string) => {
|
|
132
|
+
setNodes((n) =>
|
|
133
|
+
n.filter(
|
|
134
|
+
(node) =>
|
|
135
|
+
(key ? node.animationKey !== key : false) ||
|
|
136
|
+
node.status === 'in' ||
|
|
137
|
+
node.status === 'active'
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const newNode = useAnimationManagerNode(renderFunction);
|
|
143
|
+
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
setNodes((n) => {
|
|
146
|
+
if (!newNode) {
|
|
147
|
+
return n;
|
|
148
|
+
}
|
|
149
|
+
const existingNodeIndex = n.findIndex((node) => node.animationKey === newNode.animationKey);
|
|
150
|
+
if (existingNodeIndex >= 0) {
|
|
151
|
+
if (animation) {
|
|
152
|
+
return n.map((n2) =>
|
|
153
|
+
n2.animationKey === newNode.animationKey
|
|
154
|
+
? { ...newNode, status: 'in' }
|
|
155
|
+
: { ...n2, status: 'out' }
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
return [{ ...newNode, status: 'in' }];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [...n, newNode];
|
|
162
|
+
});
|
|
163
|
+
}, [newNode]);
|
|
164
|
+
|
|
165
|
+
function wrapNodeWithCallbacks(node: MountedAnimationNode) {
|
|
166
|
+
if (renderFunction[0] === node.animationKey) {
|
|
167
|
+
return renderFunction[1]({
|
|
168
|
+
onReady: () => {
|
|
169
|
+
if (animation) {
|
|
170
|
+
setNodes((nodes) =>
|
|
171
|
+
nodes.map((n) => (n === newNode ? { ...n, status: 'in' } : { ...n, status: 'out' }))
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
setNodes([{ ...node, status: 'in' }]);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
onAnimationFinished: () => {
|
|
178
|
+
setNodes([{ ...node, status: 'in' }]);
|
|
179
|
+
},
|
|
180
|
+
onError: () => {
|
|
181
|
+
setNodes((nodes) => nodes.map((n) => (n === node ? { ...n, status: 'errored' } : n)));
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (initial?.[0] === node.animationKey) {
|
|
186
|
+
return initial[1]({
|
|
187
|
+
onAnimationFinished: () => {
|
|
188
|
+
if (node.status === 'out') {
|
|
189
|
+
removeAllNodesOfKeyExceptShowing(node.animationKey);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
onError: () => {
|
|
193
|
+
setNodes((nodes) => nodes.map((n) => (n === node ? { ...n, status: 'errored' } : n)));
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return node.persistedElement({
|
|
198
|
+
onAnimationFinished: () => {
|
|
199
|
+
removeAllNodesOfKeyExceptShowing(node.animationKey);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
const styles = {
|
|
204
|
+
transitionDuration: `${animation?.duration || 0}ms`,
|
|
205
|
+
transitionTimingFunction: animation?.timingFunction || 'linear',
|
|
206
|
+
};
|
|
207
|
+
const classes = {
|
|
208
|
+
in: animation?.animateInClass,
|
|
209
|
+
out: animation?.animateOutClass,
|
|
210
|
+
mounted: animation?.startingClass,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<>
|
|
215
|
+
{[...nodes]
|
|
216
|
+
.filter((n) => n.status !== 'errored')
|
|
217
|
+
.map((n) => (
|
|
218
|
+
<div className={animation?.containerClass} key={n.animationKey}>
|
|
219
|
+
{wrapNodeWithCallbacks(n)(classes[n.status], styles)}
|
|
220
|
+
</div>
|
|
221
|
+
))}
|
|
222
|
+
</>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export function getTintColorStyle(tintColor?: string | null) {
|
|
5
|
+
if (!tintColor) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
filter: `url(#expo-image-tint-${tintColor})`,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type TintColorFilterProps = { tintColor?: string | null };
|
|
14
|
+
|
|
15
|
+
export default function TintColorFilter({ tintColor }: TintColorFilterProps) {
|
|
16
|
+
if (!tintColor) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return (
|
|
20
|
+
<svg style={styles.svg}>
|
|
21
|
+
<defs>
|
|
22
|
+
<filter id={`expo-image-tint-${tintColor}`} x="0" y="0" width="0" height="0">
|
|
23
|
+
<feFlood floodColor={tintColor} floodOpacity="1" result="flood" />
|
|
24
|
+
<feComposite in="flood" in2="SourceAlpha" operator="in" />
|
|
25
|
+
</filter>
|
|
26
|
+
</defs>
|
|
27
|
+
</svg>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const styles = StyleSheet.create({
|
|
32
|
+
svg: {
|
|
33
|
+
width: 0,
|
|
34
|
+
height: 0,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { useEffect, Ref } from 'react';
|
|
2
|
+
|
|
3
|
+
import ColorTintFilter, { getTintColorStyle } from './ColorTintFilter';
|
|
4
|
+
import { ImageWrapperProps } from './ImageWrapper.types';
|
|
5
|
+
import { getImageWrapperEventHandler } from './getImageWrapperEventHandler';
|
|
6
|
+
import { useHeaders, useImageHashes } from './hooks';
|
|
7
|
+
import { absoluteFilledPosition, getObjectPositionFromContentPositionObject } from './positioning';
|
|
8
|
+
import { SrcSetSource } from './useSourceSelection';
|
|
9
|
+
import { ImageNativeProps, ImageSource } from '../Image.types';
|
|
10
|
+
|
|
11
|
+
function getFetchPriorityFromImagePriority(priority: ImageNativeProps['priority'] = 'normal') {
|
|
12
|
+
return priority && ['low', 'high'].includes(priority) ? priority : 'auto';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getImgPropsFromSource(source: ImageSource | SrcSetSource | null | undefined) {
|
|
16
|
+
if (source && 'srcset' in source) {
|
|
17
|
+
return {
|
|
18
|
+
srcSet: source.srcset,
|
|
19
|
+
sizes: source.sizes,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ImageWrapper = React.forwardRef(
|
|
26
|
+
(
|
|
27
|
+
{
|
|
28
|
+
source,
|
|
29
|
+
events,
|
|
30
|
+
contentPosition,
|
|
31
|
+
hashPlaceholderContentPosition,
|
|
32
|
+
priority,
|
|
33
|
+
style,
|
|
34
|
+
hashPlaceholderStyle,
|
|
35
|
+
tintColor,
|
|
36
|
+
className,
|
|
37
|
+
accessibilityLabel,
|
|
38
|
+
cachePolicy,
|
|
39
|
+
...props
|
|
40
|
+
}: ImageWrapperProps,
|
|
41
|
+
ref: Ref<HTMLImageElement>
|
|
42
|
+
) => {
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
events?.onMount?.forEach((e) => e?.());
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
// Thumbhash uri always has to start with 'thumbhash:/'
|
|
48
|
+
const { resolvedSource, isImageHash } = useImageHashes(source);
|
|
49
|
+
const objectPosition = getObjectPositionFromContentPositionObject(
|
|
50
|
+
isImageHash ? hashPlaceholderContentPosition : contentPosition
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const sourceWithHeaders = useHeaders(resolvedSource, cachePolicy, events?.onError);
|
|
54
|
+
if (!sourceWithHeaders) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<ColorTintFilter tintColor={tintColor} />
|
|
60
|
+
<img
|
|
61
|
+
ref={ref}
|
|
62
|
+
alt={accessibilityLabel}
|
|
63
|
+
className={className}
|
|
64
|
+
src={sourceWithHeaders?.uri || undefined}
|
|
65
|
+
key={source?.uri}
|
|
66
|
+
style={{
|
|
67
|
+
objectPosition,
|
|
68
|
+
...absoluteFilledPosition,
|
|
69
|
+
...getTintColorStyle(tintColor),
|
|
70
|
+
...style,
|
|
71
|
+
...(isImageHash ? hashPlaceholderStyle : {}),
|
|
72
|
+
}}
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
// eslint-disable-next-line react/no-unknown-property
|
|
75
|
+
fetchpriority={getFetchPriorityFromImagePriority(priority || 'normal')}
|
|
76
|
+
{...getImageWrapperEventHandler(events, sourceWithHeaders)}
|
|
77
|
+
{...getImgPropsFromSource(source)}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export default ImageWrapper;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CSSProperties, SyntheticEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SrcSetSource } from './useSourceSelection';
|
|
4
|
+
import { ImageContentPositionObject, ImageProps, ImageSource } from '../Image.types';
|
|
5
|
+
|
|
6
|
+
export type OnErrorEvent =
|
|
7
|
+
| (({ source }: { source: ImageSource | null }) => void)
|
|
8
|
+
| undefined
|
|
9
|
+
| null;
|
|
10
|
+
export type OnLoadEvent =
|
|
11
|
+
| ((event: SyntheticEvent<HTMLImageElement, Event>) => void)
|
|
12
|
+
| undefined
|
|
13
|
+
| null;
|
|
14
|
+
export type OnTransitionEndEvent = (() => void) | undefined | null;
|
|
15
|
+
export type OnMountEvent = (() => void) | undefined | null;
|
|
16
|
+
|
|
17
|
+
export type ImageWrapperEvents = {
|
|
18
|
+
onLoad?: OnLoadEvent[];
|
|
19
|
+
onError?: OnErrorEvent[];
|
|
20
|
+
onTransitionEnd?: OnTransitionEndEvent[];
|
|
21
|
+
onMount?: OnMountEvent[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ImageWrapperProps = {
|
|
25
|
+
source?: ImageSource | SrcSetSource | null;
|
|
26
|
+
events?: ImageWrapperEvents;
|
|
27
|
+
contentPosition?: ImageContentPositionObject;
|
|
28
|
+
hashPlaceholderContentPosition?: ImageContentPositionObject;
|
|
29
|
+
priority?: string | null;
|
|
30
|
+
style: CSSProperties;
|
|
31
|
+
tintColor?: string | null;
|
|
32
|
+
hashPlaceholderStyle?: CSSProperties;
|
|
33
|
+
className?: string;
|
|
34
|
+
accessibilityLabel?: string;
|
|
35
|
+
cachePolicy?: ImageProps['cachePolicy'];
|
|
36
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ImageWrapperEvents } from './ImageWrapper.types';
|
|
2
|
+
import { ImageSource } from '../Image.types';
|
|
3
|
+
import { isBlurhashString } from '../utils/resolveSources';
|
|
4
|
+
|
|
5
|
+
export function getImageWrapperEventHandler(
|
|
6
|
+
events: ImageWrapperEvents | undefined,
|
|
7
|
+
source: ImageSource
|
|
8
|
+
) {
|
|
9
|
+
return {
|
|
10
|
+
onLoad: (event) => {
|
|
11
|
+
if (typeof window !== 'undefined') {
|
|
12
|
+
// this ensures the animation will run, since the starting class is applied at least 1 frame before the target class set in the onLoad event callback
|
|
13
|
+
window.requestAnimationFrame(() => {
|
|
14
|
+
events?.onLoad?.forEach((e) => e?.(event));
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
events?.onLoad?.forEach((e) => e?.(event));
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
onTransitionEnd: () => events?.onTransitionEnd?.forEach((e) => e?.()),
|
|
21
|
+
onError: () => {
|
|
22
|
+
// A temporary workaround for blurhash blobs throwing opaque errors when used in an img tag.
|
|
23
|
+
if (source?.uri && isBlurhashString(source?.uri)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
events?.onError?.forEach((e) => e?.({ source: source || null }));
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
package/src/web/hooks.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { OnErrorEvent } from './ImageWrapper.types';
|
|
4
|
+
import { ImageNativeProps, ImageSource } from '../Image.types';
|
|
5
|
+
import { useBlurhash } from '../utils/blurhash/useBlurhash';
|
|
6
|
+
import { isThumbhashString } from '../utils/resolveSources';
|
|
7
|
+
import { thumbHashStringToDataURL } from '../utils/thumbhash/thumbhash';
|
|
8
|
+
|
|
9
|
+
export function useThumbhash(source: ImageSource | null | undefined) {
|
|
10
|
+
const isThumbhash = isThumbhashString(source?.uri || '');
|
|
11
|
+
const strippedThumbhashString = source?.uri?.replace(/thumbhash:\//, '') ?? '';
|
|
12
|
+
const thumbhashSource = useMemo(
|
|
13
|
+
() => (isThumbhash ? { uri: thumbHashStringToDataURL(strippedThumbhashString) } : null),
|
|
14
|
+
[strippedThumbhashString, isThumbhash]
|
|
15
|
+
);
|
|
16
|
+
return thumbhashSource;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useImageHashes(source: ImageSource | null | undefined) {
|
|
20
|
+
const thumbhash = useThumbhash(source);
|
|
21
|
+
const blurhash = useBlurhash(source);
|
|
22
|
+
return useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
resolvedSource: blurhash ?? thumbhash ?? source,
|
|
25
|
+
isImageHash: !!blurhash || !!thumbhash,
|
|
26
|
+
}),
|
|
27
|
+
[blurhash, thumbhash]
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useHeaders(
|
|
32
|
+
source: ImageSource | null | undefined,
|
|
33
|
+
cachePolicy: ImageNativeProps['cachePolicy'],
|
|
34
|
+
onError?: OnErrorEvent[]
|
|
35
|
+
): ImageSource | null | undefined {
|
|
36
|
+
const [objectURL, setObjectURL] = useState<string | null>(null);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
(async () => {
|
|
39
|
+
if (!source?.headers || !source.uri) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = await fetch(source.uri, {
|
|
44
|
+
headers: source.headers,
|
|
45
|
+
cache: cachePolicy === 'none' ? 'no-cache' : 'default',
|
|
46
|
+
redirect: 'follow',
|
|
47
|
+
});
|
|
48
|
+
if (!result.ok) {
|
|
49
|
+
throw new Error(`Failed to fetch image: ${result.status} ${result.statusText}`);
|
|
50
|
+
}
|
|
51
|
+
const blob = await result.blob();
|
|
52
|
+
setObjectURL((prevObjURL) => {
|
|
53
|
+
if (prevObjURL) {
|
|
54
|
+
URL.revokeObjectURL(prevObjURL);
|
|
55
|
+
}
|
|
56
|
+
return URL.createObjectURL(blob);
|
|
57
|
+
});
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
} catch (error) {
|
|
60
|
+
onError?.forEach((e) => e?.({ source }));
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
}, [source]);
|
|
64
|
+
if (!source?.headers) {
|
|
65
|
+
return source;
|
|
66
|
+
}
|
|
67
|
+
if (!objectURL) {
|
|
68
|
+
// Avoid fetching a URL without headers if we have headers
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return { ...source, uri: objectURL };
|
|
72
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const style = `
|
|
2
|
+
[data-expoimage] .cross-dissolve {
|
|
3
|
+
transition-property: opacity;
|
|
4
|
+
animation-fill-mode: forwards;
|
|
5
|
+
}
|
|
6
|
+
[data-expoimage] .cross-dissolve-start:not(.transitioning) {
|
|
7
|
+
opacity: 0;
|
|
8
|
+
}
|
|
9
|
+
[data-expoimage] .cross-dissolve-active {
|
|
10
|
+
opacity: 1;
|
|
11
|
+
}
|
|
12
|
+
[data-expoimage] .cross-dissolve-end {
|
|
13
|
+
opacity: 0;
|
|
14
|
+
}
|
|
15
|
+
[data-expoimage] .flip-from-left {
|
|
16
|
+
transition-property: transform, opacity;
|
|
17
|
+
transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
|
|
18
|
+
transform-origin: center;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
[data-expoimage] .flip-from-left-container {
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
position: absolute;
|
|
25
|
+
left: 0;
|
|
26
|
+
top: 0;
|
|
27
|
+
perspective: 1000px;
|
|
28
|
+
}
|
|
29
|
+
[data-expoimage] .flip-from-left-start:not(.transitioning) {
|
|
30
|
+
transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);
|
|
31
|
+
opacity: 0;
|
|
32
|
+
}
|
|
33
|
+
[data-expoimage] .flip-from-left-active {
|
|
34
|
+
transform: translateZ(0px) rotateY(0) ;
|
|
35
|
+
opacity:1;
|
|
36
|
+
}
|
|
37
|
+
[data-expoimage] .flip-from-left-end {
|
|
38
|
+
transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);
|
|
39
|
+
opacity: 0;
|
|
40
|
+
}
|
|
41
|
+
[data-expoimage] .flip-from-right {
|
|
42
|
+
transition-property: transform, opacity;
|
|
43
|
+
transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
|
|
44
|
+
transform-origin: center;
|
|
45
|
+
}
|
|
46
|
+
[data-expoimage] .flip-from-right-container {
|
|
47
|
+
width: 100%;
|
|
48
|
+
height: 100%;
|
|
49
|
+
position: absolute;
|
|
50
|
+
left: 0;
|
|
51
|
+
top: 0;
|
|
52
|
+
perspective: 1000px;
|
|
53
|
+
}
|
|
54
|
+
[data-expoimage] .flip-from-right-start:not(.transitioning) {
|
|
55
|
+
transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);
|
|
56
|
+
opacity: 0;
|
|
57
|
+
}
|
|
58
|
+
[data-expoimage] .flip-from-right-active {
|
|
59
|
+
transform: translateZ(0px) rotateY(0) ;
|
|
60
|
+
opacity:1;
|
|
61
|
+
}
|
|
62
|
+
[data-expoimage] .flip-from-right-end {
|
|
63
|
+
transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);
|
|
64
|
+
opacity: 0;
|
|
65
|
+
}
|
|
66
|
+
[data-expoimage] .flip-from-top {
|
|
67
|
+
transition-property: transform, opacity;
|
|
68
|
+
transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
|
|
69
|
+
transform-origin: center;
|
|
70
|
+
}
|
|
71
|
+
[data-expoimage] .flip-from-top-container {
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 100%;
|
|
74
|
+
position: absolute;
|
|
75
|
+
left: 0;
|
|
76
|
+
top: 0;
|
|
77
|
+
perspective: 1000px;
|
|
78
|
+
}
|
|
79
|
+
[data-expoimage] .flip-from-top-start:not(.transitioning) {
|
|
80
|
+
transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(180deg);
|
|
81
|
+
opacity: 0;
|
|
82
|
+
}
|
|
83
|
+
[data-expoimage] .flip-from-top-active {
|
|
84
|
+
transform: translateZ(0px) rotateX(0) ;
|
|
85
|
+
opacity:1;
|
|
86
|
+
}
|
|
87
|
+
[data-expoimage] .flip-from-top-end {
|
|
88
|
+
transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(-180deg);
|
|
89
|
+
opacity: 0;
|
|
90
|
+
}
|
|
91
|
+
[data-expoimage] .flip-from-bottom {
|
|
92
|
+
transition-property: transform, opacity;
|
|
93
|
+
transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
|
|
94
|
+
transform-origin: center;
|
|
95
|
+
}
|
|
96
|
+
[data-expoimage] .flip-from-bottom-container {
|
|
97
|
+
width: 100%;
|
|
98
|
+
height: 100%;
|
|
99
|
+
position: absolute;
|
|
100
|
+
left: 0;
|
|
101
|
+
top: 0;
|
|
102
|
+
perspective: 1000px;
|
|
103
|
+
}
|
|
104
|
+
[data-expoimage] .flip-from-bottom-start:not(.transitioning) {
|
|
105
|
+
transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(-180deg);
|
|
106
|
+
opacity: 0;
|
|
107
|
+
}
|
|
108
|
+
[data-expoimage] .flip-from-bottom-active {
|
|
109
|
+
transform: translateZ(0px) rotateX(0) ;
|
|
110
|
+
opacity:1;
|
|
111
|
+
}
|
|
112
|
+
[data-expoimage] .flip-from-bottom-end {
|
|
113
|
+
transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(180deg);
|
|
114
|
+
opacity: 0;
|
|
115
|
+
}
|
|
116
|
+
[data-expoimage] .image-timing-linear {
|
|
117
|
+
--expo-image-timing: linear;
|
|
118
|
+
}
|
|
119
|
+
[data-expoimage] .image-timing-ease-in {
|
|
120
|
+
--expo-image-timing: ease-in;
|
|
121
|
+
}
|
|
122
|
+
[data-expoimage] .image-timing-ease-out {
|
|
123
|
+
--expo-image-timing: ease-out;
|
|
124
|
+
}
|
|
125
|
+
[data-expoimage] .image-timing-ease-in-out {
|
|
126
|
+
--expo-image-timing: ease-in-out;
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
export default function loadStyle() {
|
|
130
|
+
if (typeof document !== 'undefined') {
|
|
131
|
+
const styleTag = document.createElement('style');
|
|
132
|
+
styleTag.innerHTML = style;
|
|
133
|
+
styleTag.id = 'expo-image-styles';
|
|
134
|
+
document.head.appendChild(styleTag);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ImageContentPositionObject, ImageContentPositionValue } from '../Image.types';
|
|
2
|
+
|
|
3
|
+
export function ensureValueIsWebUnits(value: string | number) {
|
|
4
|
+
const trimmedValue = String(value).trim();
|
|
5
|
+
if (trimmedValue.endsWith('%')) {
|
|
6
|
+
return trimmedValue;
|
|
7
|
+
}
|
|
8
|
+
return `${trimmedValue}px`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
12
|
+
|
|
13
|
+
export const absoluteFilledPosition = {
|
|
14
|
+
width: '100%',
|
|
15
|
+
height: '100%',
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
left: 0,
|
|
18
|
+
top: 0,
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export function getObjectPositionFromContentPositionObject(
|
|
22
|
+
contentPosition?: ImageContentPositionObject
|
|
23
|
+
): string {
|
|
24
|
+
const resolvedPosition = { ...contentPosition } as Record<
|
|
25
|
+
KeysOfUnion<ImageContentPositionObject>,
|
|
26
|
+
ImageContentPositionValue
|
|
27
|
+
>;
|
|
28
|
+
if (!resolvedPosition) {
|
|
29
|
+
return '50% 50%';
|
|
30
|
+
}
|
|
31
|
+
if (resolvedPosition.top == null && resolvedPosition.bottom == null) {
|
|
32
|
+
resolvedPosition.top = '50%';
|
|
33
|
+
}
|
|
34
|
+
if (resolvedPosition.left == null && resolvedPosition.right == null) {
|
|
35
|
+
resolvedPosition.left = '50%';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
['top', 'bottom', 'left', 'right']
|
|
40
|
+
.map((key) => {
|
|
41
|
+
if (key in resolvedPosition) {
|
|
42
|
+
return `${key} ${ensureValueIsWebUnits(resolvedPosition[key])}`;
|
|
43
|
+
}
|
|
44
|
+
return '';
|
|
45
|
+
})
|
|
46
|
+
.join(' ') || '50% 50%'
|
|
47
|
+
);
|
|
48
|
+
}
|