zkit-ui 2.0.5 → 2.0.7
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/README.md +1 -1
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryLayoutSupport.java → NativeImagePreviewLayoutSupport.java} +12 -12
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryMediaItem.java → NativeImagePreviewMediaItem.java} +2 -2
- package/android/src/main/java/cn/fontree/zkit/ui/preview/NativeImagePreviewModule.kt +43 -0
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryPagerAdapter.java → NativeImagePreviewPagerAdapter.java} +18 -18
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySharedElementGeometry.java → NativeImagePreviewSharedElementGeometry.java} +2 -2
- package/android/src/main/java/cn/fontree/zkit/ui/preview/NativeImagePreviewSharedElementNames.java +39 -0
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySharedElementState.java → NativeImagePreviewSharedElementState.java} +4 -4
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySourceViewRegistry.java → NativeImagePreviewSourceViewRegistry.java} +2 -2
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryTransitionSnapshotView.java → NativeImagePreviewTransitionSnapshotView.java} +3 -3
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryVideoPlayerView.java → NativeImagePreviewVideoPlayerView.java} +7 -7
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GaleriaView.kt → NativeImagePreviewView.kt} +18 -18
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerOverlayView.java → NativeImagePreviewViewerOverlayView.java} +49 -49
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerPageView.java → NativeImagePreviewViewerPageView.java} +27 -27
- package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerTransitionController.java → NativeImagePreviewViewerTransitionController.java} +22 -22
- package/dist/ui/Button/index.d.ts +1 -1
- package/dist/ui/Button/index.d.ts.map +1 -1
- package/dist/ui/Button/index.js +18 -3
- package/dist/ui/NativeImagePreview/NativeImagePreview.js +6 -6
- package/dist/ui/NativeImagePreview/NativeImagePreview.web.d.ts +1 -0
- package/dist/ui/NativeImagePreview/NativeImagePreview.web.d.ts.map +1 -1
- package/dist/ui/NativeImagePreview/NativeImagePreview.web.js +105 -11
- package/dist/ui/NativeImagePreview/context.d.ts +1 -1
- package/dist/ui/NativeImagePreview/context.d.ts.map +1 -1
- package/dist/ui/NativeImagePreview/types.d.ts +3 -1
- package/dist/ui/NativeImagePreview/types.d.ts.map +1 -1
- package/dist/ui/NativeImagePreview/utils.d.ts.map +1 -1
- package/dist/ui/NativeImagePreview/utils.js +1 -0
- package/dist/ui/NativeImagePreview/web/geometry.d.ts +20 -0
- package/dist/ui/NativeImagePreview/web/geometry.d.ts.map +1 -0
- package/dist/ui/NativeImagePreview/web/geometry.js +121 -0
- package/dist/ui/NativeImagePreview/web/media.d.ts +6 -0
- package/dist/ui/NativeImagePreview/web/media.d.ts.map +1 -0
- package/dist/ui/NativeImagePreview/web/media.js +90 -0
- package/dist/ui/NativeImagePreview/web/styles.css +137 -0
- package/dist/ui/NativeImagePreview/web/transition.d.ts +15 -0
- package/dist/ui/NativeImagePreview/web/transition.d.ts.map +1 -0
- package/dist/ui/NativeImagePreview/web/transition.js +77 -0
- package/dist/ui/NativeImagePreview/web/types.d.ts +74 -0
- package/dist/ui/NativeImagePreview/web/types.d.ts.map +1 -0
- package/dist/ui/NativeImagePreview/web/types.js +3 -0
- package/dist/ui/NativeImagePreview/web/viewer.d.ts +104 -0
- package/dist/ui/NativeImagePreview/web/viewer.d.ts.map +1 -0
- package/dist/ui/NativeImagePreview/web/viewer.js +894 -0
- package/expo-module.config.json +2 -2
- package/ios/{GalleryViewer/GaleriaImageLoader.swift → NativeImagePreview/NativeImagePreviewImageLoader.swift} +7 -7
- package/ios/NativeImagePreview/NativeImagePreviewImageViewInteraction.swift +245 -0
- package/ios/{GalleryViewer/GaleriaLayoutSupport.swift → NativeImagePreview/NativeImagePreviewLayoutSupport.swift} +19 -19
- package/ios/NativeImagePreview/NativeImagePreviewMedia.swift +28 -0
- package/ios/NativeImagePreview/NativeImagePreviewSourceViewRegistry.swift +80 -0
- package/ios/{GalleryViewer/GaleriaVideoPlayerView.swift → NativeImagePreview/NativeImagePreviewVideoPlayerView.swift} +1 -1
- package/ios/{GalleryViewer/GaleriaViewerConfiguration.swift → NativeImagePreview/NativeImagePreviewViewerConfiguration.swift} +7 -7
- package/ios/{GalleryViewer/GaleriaViewerController.swift → NativeImagePreview/NativeImagePreviewViewerController.swift} +36 -36
- package/ios/{GalleryViewer/GaleriaViewerPageView.swift → NativeImagePreview/NativeImagePreviewViewerPageView.swift} +33 -33
- package/ios/{GalleryViewer/GaleriaViewerTransitionCoordinator.swift → NativeImagePreview/NativeImagePreviewViewerTransitionCoordinator.swift} +16 -16
- package/ios/{GaleriaModule.swift → NativeImagePreviewModule.swift} +4 -4
- package/ios/{GaleriaView.swift → NativeImagePreviewView.swift} +26 -27
- package/package.json +18 -12
- package/src/services/ImagePreviewService/README.md +1 -1
- package/src/types.d.ts +1 -0
- package/src/ui/Button/README.md +1 -1
- package/src/ui/Button/index.tsx +27 -7
- package/src/ui/NativeImagePreview/NativeImagePreview.tsx +7 -7
- package/src/ui/NativeImagePreview/NativeImagePreview.web.tsx +175 -11
- package/src/ui/NativeImagePreview/README.md +3 -3
- package/src/ui/NativeImagePreview/context.tsx +1 -1
- package/src/ui/NativeImagePreview/types.ts +3 -1
- package/src/ui/NativeImagePreview/utils.ts +1 -0
- package/src/ui/NativeImagePreview/web/geometry.ts +134 -0
- package/src/ui/NativeImagePreview/web/media.ts +91 -0
- package/src/ui/NativeImagePreview/web/styles.css +137 -0
- package/src/ui/NativeImagePreview/web/transition.ts +111 -0
- package/src/ui/NativeImagePreview/web/types.ts +88 -0
- package/src/ui/NativeImagePreview/web/viewer.ts +1024 -0
- package/android/src/main/java/cn/fontree/zkit/ui/preview/GaleriaModule.kt +0 -43
- package/android/src/main/java/cn/fontree/zkit/ui/preview/GallerySharedElementNames.java +0 -39
- package/ios/GalleryViewer/GaleriaImageViewInteraction.swift +0 -245
- package/ios/GalleryViewer/GaleriaMedia.swift +0 -28
- package/ios/GalleryViewer/GaleriaSourceViewRegistry.swift +0 -80
- /package/android/src/main/res/layout/{galeria_player_view.xml → native_image_preview_player_view.xml} +0 -0
package/README.md
CHANGED
|
@@ -263,7 +263,7 @@ const styles = StyleSheet.create({
|
|
|
263
263
|
});
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
`NativeImagePreview` 不是 `ImagePreview`
|
|
266
|
+
`NativeImagePreview` 不是 `ImagePreview` 的命令式替代品,而是面向真实缩略图锚点的共享转场组件。`items` 顺序必须和 `NativeImagePreview.Item index` 对齐,`Item` 内必须渲染真实图片节点;iOS / Android 走原生 viewer,原生模块未注册时不会降级到普通 `ImagePreview`,需要重建 native app;Web 走 H5 viewer,支持共享转场、缩放、滑动、视频播放和拖拽关闭。
|
|
267
267
|
|
|
268
268
|
### 目录与导出
|
|
269
269
|
|
|
@@ -15,19 +15,19 @@ import androidx.annotation.Nullable;
|
|
|
15
15
|
|
|
16
16
|
import com.github.chrisbanes.photoview.PhotoView;
|
|
17
17
|
|
|
18
|
-
public final class
|
|
18
|
+
public final class NativeImagePreviewLayoutSupport {
|
|
19
19
|
private static final int MAX_TRANSITION_BITMAP_SIDE = 2048;
|
|
20
20
|
|
|
21
|
-
private
|
|
21
|
+
private NativeImagePreviewLayoutSupport() {
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@Nullable
|
|
25
|
-
public static
|
|
25
|
+
public static NativeImagePreviewSharedElementState captureImageViewState(@Nullable ImageView imageView) {
|
|
26
26
|
return captureImageViewState(imageView, null);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
@Nullable
|
|
30
|
-
public static
|
|
30
|
+
public static NativeImagePreviewSharedElementState captureImageViewState(@Nullable ImageView imageView, @Nullable RectF clippingFrameInWindow) {
|
|
31
31
|
if (imageView == null) {
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
@@ -72,14 +72,14 @@ public final class GalleryLayoutSupport {
|
|
|
72
72
|
contentFrameInWindow.bottom - visibleFrameInWindow.top
|
|
73
73
|
);
|
|
74
74
|
|
|
75
|
-
return new
|
|
75
|
+
return new NativeImagePreviewSharedElementState(
|
|
76
76
|
transitionDrawable,
|
|
77
|
-
new
|
|
77
|
+
new NativeImagePreviewSharedElementGeometry(visibleFrameInWindow, contentFrameInVisibleBounds)
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
@Nullable
|
|
82
|
-
public static
|
|
82
|
+
public static NativeImagePreviewSharedElementGeometry captureImageViewGeometry(@Nullable ImageView imageView, @Nullable Drawable geometryDrawable) {
|
|
83
83
|
if (imageView == null || imageView.getWidth() <= 0 || imageView.getHeight() <= 0) {
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
@@ -117,7 +117,7 @@ public final class GalleryLayoutSupport {
|
|
|
117
117
|
contentFrameInWindow.bottom - visibleFrameInWindow.top
|
|
118
118
|
);
|
|
119
119
|
|
|
120
|
-
return new
|
|
120
|
+
return new NativeImagePreviewSharedElementGeometry(visibleFrameInWindow, contentFrameInVisibleBounds);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
@NonNull
|
|
@@ -225,16 +225,16 @@ public final class GalleryLayoutSupport {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
@NonNull
|
|
228
|
-
public static
|
|
228
|
+
public static NativeImagePreviewSharedElementGeometry defaultGeometryFor(@NonNull Drawable drawable, @NonNull RectF containerBounds) {
|
|
229
229
|
RectF visibleFrame = aspectFitRect(drawable, containerBounds);
|
|
230
|
-
return new
|
|
230
|
+
return new NativeImagePreviewSharedElementGeometry(
|
|
231
231
|
visibleFrame,
|
|
232
232
|
new RectF(0f, 0f, visibleFrame.width(), visibleFrame.height())
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
@NonNull
|
|
237
|
-
public static
|
|
237
|
+
public static NativeImagePreviewSharedElementGeometry defaultGeometryForAspectRatio(float width, float height, @NonNull RectF containerBounds) {
|
|
238
238
|
float safeWidth = Math.max(1f, width);
|
|
239
239
|
float safeHeight = Math.max(1f, height);
|
|
240
240
|
float widthScale = containerBounds.width() / safeWidth;
|
|
@@ -245,7 +245,7 @@ public final class GalleryLayoutSupport {
|
|
|
245
245
|
float left = containerBounds.left + (containerBounds.width() - targetWidth) * 0.5f;
|
|
246
246
|
float top = containerBounds.top + (containerBounds.height() - targetHeight) * 0.5f;
|
|
247
247
|
RectF visibleFrame = new RectF(left, top, left + targetWidth, top + targetHeight);
|
|
248
|
-
return new
|
|
248
|
+
return new NativeImagePreviewSharedElementGeometry(
|
|
249
249
|
visibleFrame,
|
|
250
250
|
new RectF(0f, 0f, visibleFrame.width(), visibleFrame.height())
|
|
251
251
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
package cn.fontree.zkit.ui.preview;
|
|
2
2
|
|
|
3
|
-
public class
|
|
3
|
+
public class NativeImagePreviewMediaItem {
|
|
4
4
|
public enum MediaType {
|
|
5
5
|
IMAGE,
|
|
6
6
|
VIDEO
|
|
@@ -11,7 +11,7 @@ public class GalleryMediaItem {
|
|
|
11
11
|
private final String sourceUrl;
|
|
12
12
|
private final String thumbnailUrl;
|
|
13
13
|
|
|
14
|
-
public
|
|
14
|
+
public NativeImagePreviewMediaItem(String id, MediaType mediaType, String sourceUrl, String thumbnailUrl) {
|
|
15
15
|
this.id = id;
|
|
16
16
|
this.mediaType = mediaType;
|
|
17
17
|
this.sourceUrl = sourceUrl;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package cn.fontree.zkit.ui.preview
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.modules.Module
|
|
4
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
|
|
6
|
+
class NativeImagePreviewModule : Module() {
|
|
7
|
+
override fun definition() = ModuleDefinition {
|
|
8
|
+
Name("ZKitNativeImagePreview")
|
|
9
|
+
|
|
10
|
+
View(NativeImagePreviewView::class) {
|
|
11
|
+
Events(
|
|
12
|
+
"onIndexChange"
|
|
13
|
+
)
|
|
14
|
+
Prop("theme") { view: NativeImagePreviewView, theme: Theme ->
|
|
15
|
+
view.theme = theme
|
|
16
|
+
}
|
|
17
|
+
Prop("items") { view: NativeImagePreviewView, items: Array<Map<String, Any?>> ->
|
|
18
|
+
view.items = items.toList()
|
|
19
|
+
}
|
|
20
|
+
Prop("urls") { view: NativeImagePreviewView, urls: Array<String> ->
|
|
21
|
+
view.urls = urls
|
|
22
|
+
}
|
|
23
|
+
Prop("index") { view: NativeImagePreviewView, index: Int ->
|
|
24
|
+
view.initialIndex = index
|
|
25
|
+
}
|
|
26
|
+
Prop("previewGroupId") { view: NativeImagePreviewView, previewGroupId: String? ->
|
|
27
|
+
view.previewGroupId = previewGroupId
|
|
28
|
+
}
|
|
29
|
+
Prop("disableHiddenOriginalImage") { view: NativeImagePreviewView, disableHiddenOriginalImage: Boolean ->
|
|
30
|
+
view.disableHiddenOriginalImage = disableHiddenOriginalImage
|
|
31
|
+
}
|
|
32
|
+
Prop("edgeToEdge") { view: NativeImagePreviewView, edgeToEdge: Boolean ->
|
|
33
|
+
view.edgeToEdge = edgeToEdge
|
|
34
|
+
}
|
|
35
|
+
Prop("transitionOffsetY") { view: NativeImagePreviewView, transitionOffsetY: Int? ->
|
|
36
|
+
view.transitionOffsetY = transitionOffsetY
|
|
37
|
+
}
|
|
38
|
+
Prop("transitionOffsetX") { view: NativeImagePreviewView, transitionOffsetX: Int? ->
|
|
39
|
+
view.transitionOffsetX = transitionOffsetX
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -11,28 +11,28 @@ import java.util.HashMap;
|
|
|
11
11
|
import java.util.List;
|
|
12
12
|
import java.util.Map;
|
|
13
13
|
|
|
14
|
-
public final class
|
|
14
|
+
public final class NativeImagePreviewPagerAdapter extends RecyclerView.Adapter<NativeImagePreviewPagerAdapter.PageViewHolder> {
|
|
15
15
|
public interface PageBindCallback {
|
|
16
|
-
void onPageBound(@NonNull
|
|
16
|
+
void onPageBound(@NonNull NativeImagePreviewViewerPageView pageView, int position);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
private final List<
|
|
20
|
-
private final Map<Integer,
|
|
19
|
+
private final List<NativeImagePreviewMediaItem> items = new ArrayList<>();
|
|
20
|
+
private final Map<Integer, NativeImagePreviewViewerPageView> attachedViews = new HashMap<>();
|
|
21
21
|
@Nullable
|
|
22
|
-
private final
|
|
22
|
+
private final NativeImagePreviewViewerPageView.Listener pageListener;
|
|
23
23
|
@Nullable
|
|
24
24
|
private final PageBindCallback pageBindCallback;
|
|
25
25
|
private int activeIndex = -1;
|
|
26
26
|
|
|
27
|
-
public
|
|
28
|
-
@Nullable
|
|
27
|
+
public NativeImagePreviewPagerAdapter(
|
|
28
|
+
@Nullable NativeImagePreviewViewerPageView.Listener pageListener,
|
|
29
29
|
@Nullable PageBindCallback pageBindCallback
|
|
30
30
|
) {
|
|
31
31
|
this.pageListener = pageListener;
|
|
32
32
|
this.pageBindCallback = pageBindCallback;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public void setItems(@NonNull List<
|
|
35
|
+
public void setItems(@NonNull List<NativeImagePreviewMediaItem> list) {
|
|
36
36
|
attachedViews.clear();
|
|
37
37
|
items.clear();
|
|
38
38
|
items.addAll(list);
|
|
@@ -41,21 +41,21 @@ public final class GalleryPagerAdapter extends RecyclerView.Adapter<GalleryPager
|
|
|
41
41
|
|
|
42
42
|
public void setActiveIndex(int index) {
|
|
43
43
|
activeIndex = index;
|
|
44
|
-
for (Map.Entry<Integer,
|
|
44
|
+
for (Map.Entry<Integer, NativeImagePreviewViewerPageView> entry : attachedViews.entrySet()) {
|
|
45
45
|
entry.getValue().setActive(entry.getKey() == index);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
public void releaseAll() {
|
|
50
|
-
for (
|
|
50
|
+
for (NativeImagePreviewViewerPageView view : attachedViews.values()) {
|
|
51
51
|
view.release();
|
|
52
52
|
}
|
|
53
53
|
attachedViews.clear();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
@Nullable
|
|
57
|
-
public
|
|
58
|
-
|
|
57
|
+
public NativeImagePreviewViewerPageView findAttachedView(int position) {
|
|
58
|
+
NativeImagePreviewViewerPageView pageView = attachedViews.get(position);
|
|
59
59
|
if (pageView == null) {
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
@@ -67,14 +67,14 @@ public final class GalleryPagerAdapter extends RecyclerView.Adapter<GalleryPager
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
@Nullable
|
|
70
|
-
public
|
|
70
|
+
public NativeImagePreviewViewerPageView findActiveView() {
|
|
71
71
|
return attachedViews.get(activeIndex);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
@NonNull
|
|
75
75
|
@Override
|
|
76
76
|
public PageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
77
|
-
|
|
77
|
+
NativeImagePreviewViewerPageView pageView = new NativeImagePreviewViewerPageView(parent.getContext());
|
|
78
78
|
pageView.setListener(pageListener);
|
|
79
79
|
return new PageViewHolder(pageView);
|
|
80
80
|
}
|
|
@@ -112,9 +112,9 @@ public final class GalleryPagerAdapter extends RecyclerView.Adapter<GalleryPager
|
|
|
112
112
|
holder.pageView.release();
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
private void removeAttachedViewKeys(@NonNull
|
|
115
|
+
private void removeAttachedViewKeys(@NonNull NativeImagePreviewViewerPageView pageView) {
|
|
116
116
|
List<Integer> keys = new ArrayList<>();
|
|
117
|
-
for (Map.Entry<Integer,
|
|
117
|
+
for (Map.Entry<Integer, NativeImagePreviewViewerPageView> entry : attachedViews.entrySet()) {
|
|
118
118
|
if (entry.getValue() == pageView) {
|
|
119
119
|
keys.add(entry.getKey());
|
|
120
120
|
}
|
|
@@ -130,9 +130,9 @@ public final class GalleryPagerAdapter extends RecyclerView.Adapter<GalleryPager
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
static final class PageViewHolder extends RecyclerView.ViewHolder {
|
|
133
|
-
final
|
|
133
|
+
final NativeImagePreviewViewerPageView pageView;
|
|
134
134
|
|
|
135
|
-
PageViewHolder(@NonNull
|
|
135
|
+
PageViewHolder(@NonNull NativeImagePreviewViewerPageView itemView) {
|
|
136
136
|
super(itemView);
|
|
137
137
|
this.pageView = itemView;
|
|
138
138
|
}
|
|
@@ -4,11 +4,11 @@ import android.graphics.RectF;
|
|
|
4
4
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
6
|
|
|
7
|
-
public final class
|
|
7
|
+
public final class NativeImagePreviewSharedElementGeometry {
|
|
8
8
|
private final RectF visibleFrameInWindow;
|
|
9
9
|
private final RectF contentFrameInVisibleBounds;
|
|
10
10
|
|
|
11
|
-
public
|
|
11
|
+
public NativeImagePreviewSharedElementGeometry(@NonNull RectF visibleFrameInWindow, @NonNull RectF contentFrameInVisibleBounds) {
|
|
12
12
|
this.visibleFrameInWindow = new RectF(visibleFrameInWindow);
|
|
13
13
|
this.contentFrameInVisibleBounds = new RectF(contentFrameInVisibleBounds);
|
|
14
14
|
}
|
package/android/src/main/java/cn/fontree/zkit/ui/preview/NativeImagePreviewSharedElementNames.java
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package cn.fontree.zkit.ui.preview;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public final class NativeImagePreviewSharedElementNames {
|
|
7
|
+
private static final String PREFIX = "zkit-native-image-preview:media:";
|
|
8
|
+
|
|
9
|
+
private NativeImagePreviewSharedElementNames() {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@NonNull
|
|
13
|
+
public static String forItem(@NonNull NativeImagePreviewMediaItem item) {
|
|
14
|
+
return forItem(null, item);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
public static String forItem(@Nullable String previewGroupId, @NonNull NativeImagePreviewMediaItem item) {
|
|
19
|
+
return forId(previewGroupId, item.getId());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@NonNull
|
|
23
|
+
public static String forIndex(int index) {
|
|
24
|
+
return forIndex(null, index);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@NonNull
|
|
28
|
+
public static String forIndex(@Nullable String previewGroupId, int index) {
|
|
29
|
+
return forId(previewGroupId, String.valueOf(index));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@NonNull
|
|
33
|
+
private static String forId(@Nullable String previewGroupId, @NonNull String id) {
|
|
34
|
+
if (previewGroupId == null || previewGroupId.isEmpty()) {
|
|
35
|
+
return PREFIX + id;
|
|
36
|
+
}
|
|
37
|
+
return PREFIX + previewGroupId + ":" + id;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -4,11 +4,11 @@ import android.graphics.drawable.Drawable;
|
|
|
4
4
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
6
|
|
|
7
|
-
public final class
|
|
7
|
+
public final class NativeImagePreviewSharedElementState {
|
|
8
8
|
private final Drawable drawable;
|
|
9
|
-
private final
|
|
9
|
+
private final NativeImagePreviewSharedElementGeometry geometry;
|
|
10
10
|
|
|
11
|
-
public
|
|
11
|
+
public NativeImagePreviewSharedElementState(@NonNull Drawable drawable, @NonNull NativeImagePreviewSharedElementGeometry geometry) {
|
|
12
12
|
this.drawable = drawable;
|
|
13
13
|
this.geometry = geometry;
|
|
14
14
|
}
|
|
@@ -19,7 +19,7 @@ public final class GallerySharedElementState {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
@NonNull
|
|
22
|
-
public
|
|
22
|
+
public NativeImagePreviewSharedElementGeometry getGeometry() {
|
|
23
23
|
return geometry;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -12,10 +12,10 @@ import java.util.HashMap;
|
|
|
12
12
|
import java.util.Iterator;
|
|
13
13
|
import java.util.Map;
|
|
14
14
|
|
|
15
|
-
public final class
|
|
15
|
+
public final class NativeImagePreviewSourceViewRegistry {
|
|
16
16
|
private static final Map<String, WeakReference<ImageView>> SOURCE_VIEWS = new HashMap<>();
|
|
17
17
|
|
|
18
|
-
private
|
|
18
|
+
private NativeImagePreviewSourceViewRegistry() {
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public static synchronized void register(@NonNull String key, @NonNull ImageView imageView) {
|
|
@@ -9,10 +9,10 @@ import android.widget.ImageView;
|
|
|
9
9
|
|
|
10
10
|
import androidx.annotation.NonNull;
|
|
11
11
|
|
|
12
|
-
public final class
|
|
12
|
+
public final class NativeImagePreviewTransitionSnapshotView extends FrameLayout {
|
|
13
13
|
private final ImageView imageView;
|
|
14
14
|
|
|
15
|
-
public
|
|
15
|
+
public NativeImagePreviewTransitionSnapshotView(@NonNull Context context, @NonNull Drawable drawable) {
|
|
16
16
|
super(context);
|
|
17
17
|
setClipChildren(true);
|
|
18
18
|
setClipToPadding(true);
|
|
@@ -22,7 +22,7 @@ public final class GalleryTransitionSnapshotView extends FrameLayout {
|
|
|
22
22
|
addView(imageView);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public void applyGeometry(@NonNull
|
|
25
|
+
public void applyGeometry(@NonNull NativeImagePreviewSharedElementGeometry geometry) {
|
|
26
26
|
RectF visibleFrame = geometry.getVisibleFrameInWindow();
|
|
27
27
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();
|
|
28
28
|
if (layoutParams == null) {
|
|
@@ -29,7 +29,7 @@ import com.bumptech.glide.load.engine.GlideException;
|
|
|
29
29
|
import com.bumptech.glide.request.RequestListener;
|
|
30
30
|
import com.bumptech.glide.request.target.Target;
|
|
31
31
|
|
|
32
|
-
public final class
|
|
32
|
+
public final class NativeImagePreviewVideoPlayerView extends FrameLayout {
|
|
33
33
|
public interface Listener {
|
|
34
34
|
void onCloseRequested();
|
|
35
35
|
}
|
|
@@ -40,7 +40,7 @@ public final class GalleryVideoPlayerView extends FrameLayout {
|
|
|
40
40
|
@Nullable
|
|
41
41
|
private Runnable contentReadyListener;
|
|
42
42
|
@Nullable
|
|
43
|
-
private
|
|
43
|
+
private NativeImagePreviewMediaItem item;
|
|
44
44
|
@Nullable
|
|
45
45
|
private ExoPlayer player;
|
|
46
46
|
@Nullable
|
|
@@ -60,7 +60,7 @@ public final class GalleryVideoPlayerView extends FrameLayout {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
public
|
|
63
|
+
public NativeImagePreviewVideoPlayerView(@NonNull Context context) {
|
|
64
64
|
super(context);
|
|
65
65
|
setLayoutParams(new LayoutParams(
|
|
66
66
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
@@ -78,7 +78,7 @@ public final class GalleryVideoPlayerView extends FrameLayout {
|
|
|
78
78
|
addView(posterImageView);
|
|
79
79
|
|
|
80
80
|
playerView = (PlayerView) LayoutInflater.from(context)
|
|
81
|
-
.inflate(R.layout.
|
|
81
|
+
.inflate(R.layout.native_image_preview_player_view, this, false);
|
|
82
82
|
playerView.setUseController(true);
|
|
83
83
|
playerView.setControllerAutoShow(true);
|
|
84
84
|
playerView.setControllerHideOnTouch(true);
|
|
@@ -134,7 +134,7 @@ public final class GalleryVideoPlayerView extends FrameLayout {
|
|
|
134
134
|
this.contentReadyListener = contentReadyListener;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
public void bind(@NonNull
|
|
137
|
+
public void bind(@NonNull NativeImagePreviewMediaItem item) {
|
|
138
138
|
this.item = item;
|
|
139
139
|
firstFrameReady = false;
|
|
140
140
|
playerView.animate().cancel();
|
|
@@ -194,8 +194,8 @@ public final class GalleryVideoPlayerView extends FrameLayout {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
@Nullable
|
|
197
|
-
public
|
|
198
|
-
return
|
|
197
|
+
public NativeImagePreviewSharedElementState sharedElementState() {
|
|
198
|
+
return NativeImagePreviewLayoutSupport.captureImageViewState(posterImageView);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
@Nullable
|
|
@@ -15,7 +15,7 @@ enum class Theme(val value: String) {
|
|
|
15
15
|
Light("light")
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
class
|
|
18
|
+
class NativeImagePreviewView(context: Context) : ViewGroup(context) {
|
|
19
19
|
var urls: Array<String>? = null
|
|
20
20
|
var items: List<Map<String, Any?>> = emptyList()
|
|
21
21
|
var theme: Theme = Theme.Dark
|
|
@@ -24,7 +24,7 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
24
24
|
field = value
|
|
25
25
|
bindSourceImageView()
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var previewGroupId: String? = null
|
|
28
28
|
set(value) {
|
|
29
29
|
field = value
|
|
30
30
|
bindSourceImageView()
|
|
@@ -39,7 +39,7 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
39
39
|
private var observedSourceImageView: ImageView? = null
|
|
40
40
|
private var sourceImageLayoutListener: View.OnLayoutChangeListener? = null
|
|
41
41
|
private var sourceImageAttachListener: View.OnAttachStateChangeListener? = null
|
|
42
|
-
private var overlayView:
|
|
42
|
+
private var overlayView: NativeImagePreviewViewerOverlayView? = null
|
|
43
43
|
private var overlayBackCallback: OnBackPressedCallback? = null
|
|
44
44
|
|
|
45
45
|
override fun onAttachedToWindow() {
|
|
@@ -64,14 +64,14 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
64
64
|
unregisterSourceImageView()
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
private fun
|
|
67
|
+
private fun scopedPreviewGroupId(): String? = previewGroupId?.takeIf { it.isNotBlank() }
|
|
68
68
|
|
|
69
69
|
private fun transitionNameForIndex(index: Int): String {
|
|
70
|
-
return
|
|
70
|
+
return NativeImagePreviewSharedElementNames.forIndex(scopedPreviewGroupId(), index)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
private fun transitionNameForItem(item:
|
|
74
|
-
return
|
|
73
|
+
private fun transitionNameForItem(item: NativeImagePreviewMediaItem): String {
|
|
74
|
+
return NativeImagePreviewSharedElementNames.forItem(scopedPreviewGroupId(), item)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
private fun bindSourceImageView() {
|
|
@@ -85,7 +85,7 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
85
85
|
if (previousSourceImageView != null && previousSourceImageView !== imageView) {
|
|
86
86
|
clearSourceImageObserver()
|
|
87
87
|
if (!isSourceImageViewUsable(previousSourceImageView)) {
|
|
88
|
-
|
|
88
|
+
NativeImagePreviewSourceViewRegistry.unregisterView(previousSourceImageView)
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -110,14 +110,14 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
110
110
|
?: activity.findViewById<ViewGroup>(android.R.id.content)
|
|
111
111
|
?: return
|
|
112
112
|
val sourceKey = transitionNameForItem(mediaItems[safeIndex])
|
|
113
|
-
|
|
114
|
-
val overlay =
|
|
113
|
+
NativeImagePreviewSourceViewRegistry.register(sourceKey, sourceView)
|
|
114
|
+
val overlay = NativeImagePreviewViewerOverlayView(
|
|
115
115
|
activity,
|
|
116
116
|
mediaItems,
|
|
117
117
|
safeIndex,
|
|
118
118
|
theme == Theme.Light,
|
|
119
|
-
|
|
120
|
-
object :
|
|
119
|
+
scopedPreviewGroupId(),
|
|
120
|
+
object : NativeImagePreviewViewerOverlayView.Listener {
|
|
121
121
|
override fun onOverlayDismissed() {
|
|
122
122
|
if (overlayView != null) {
|
|
123
123
|
overlayView = null
|
|
@@ -145,22 +145,22 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
private fun buildMediaItems(): List<
|
|
148
|
+
private fun buildMediaItems(): List<NativeImagePreviewMediaItem> {
|
|
149
149
|
if (items.isNotEmpty()) {
|
|
150
150
|
return items.mapIndexedNotNull { index, data ->
|
|
151
151
|
val type = data["type"] as? String ?: return@mapIndexedNotNull null
|
|
152
152
|
val url = data["url"] as? String ?: return@mapIndexedNotNull null
|
|
153
153
|
if (type.lowercase() == "video") {
|
|
154
154
|
val poster = data["poster"] as? String ?: url
|
|
155
|
-
|
|
155
|
+
NativeImagePreviewMediaItem(index.toString(), NativeImagePreviewMediaItem.MediaType.VIDEO, url, poster)
|
|
156
156
|
} else {
|
|
157
|
-
|
|
157
|
+
NativeImagePreviewMediaItem(index.toString(), NativeImagePreviewMediaItem.MediaType.IMAGE, url, url)
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
val rawUrls = urls ?: return emptyList()
|
|
162
162
|
return rawUrls.mapIndexed { index, url ->
|
|
163
|
-
|
|
163
|
+
NativeImagePreviewMediaItem(index.toString(), NativeImagePreviewMediaItem.MediaType.IMAGE, url, url)
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -191,7 +191,7 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
191
191
|
val transitionName = transitionNameForIndex(initialIndex)
|
|
192
192
|
if (isSourceImageViewUsable(imageView)) {
|
|
193
193
|
clearSourceImageObserver(imageView)
|
|
194
|
-
|
|
194
|
+
NativeImagePreviewSourceViewRegistry.register(transitionName, imageView)
|
|
195
195
|
return
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -298,7 +298,7 @@ class GaleriaView(context: Context) : ViewGroup(context) {
|
|
|
298
298
|
private fun unregisterSourceImageView() {
|
|
299
299
|
clearSourceImageObserver()
|
|
300
300
|
sourceImageView?.let { imageView ->
|
|
301
|
-
|
|
301
|
+
NativeImagePreviewSourceViewRegistry.unregisterView(imageView)
|
|
302
302
|
}
|
|
303
303
|
sourceImageView = null
|
|
304
304
|
}
|