@onekeyfe/react-native-native-overlay 6.7.0-alpha.466 → 6.8.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +119 -21
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPageHostView.kt +14 -3
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
  6. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
  7. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayPageHostLayoutTest.kt +58 -0
  8. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
  9. package/docs/SPEC.md +202 -24
  10. package/ios/NativeOverlayContainerView.swift +6 -0
  11. package/ios/NativeOverlayWindowManager.swift +244 -7
  12. package/lib/module/NativeOverlayNativeComponent.ts +13 -0
  13. package/lib/module/OverlayView.js +7 -1
  14. package/lib/module/OverlayView.js.map +1 -1
  15. package/lib/module/animation/anchoredOrigin.js +26 -0
  16. package/lib/module/animation/anchoredOrigin.js.map +1 -0
  17. package/lib/module/animation/resolveAnimation.js +26 -4
  18. package/lib/module/animation/resolveAnimation.js.map +1 -1
  19. package/lib/module/index.js +1 -0
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/module/web/animateTransition.js +38 -12
  22. package/lib/module/web/animateTransition.js.map +1 -1
  23. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
  24. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
  25. package/lib/typescript/src/OverlayView.d.ts.map +1 -1
  26. package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
  27. package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
  28. package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
  29. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
  30. package/lib/typescript/src/animation/types.d.ts +5 -1
  31. package/lib/typescript/src/animation/types.d.ts.map +1 -1
  32. package/lib/typescript/src/index.d.ts +1 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -1
  34. package/lib/typescript/src/web/animateTransition.d.ts +12 -0
  35. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/NativeOverlayNativeComponent.ts +13 -0
  38. package/src/OverlayView.tsx +7 -0
  39. package/src/animation/anchoredOrigin.ts +35 -0
  40. package/src/animation/resolveAnimation.ts +28 -7
  41. package/src/animation/types.ts +5 -1
  42. package/src/index.ts +1 -0
  43. package/src/web/animateTransition.ts +54 -14
@@ -57,7 +57,11 @@ export interface IOverlayTransition {
57
57
 
58
58
  export interface IOverlayAnimation {
59
59
  enter?: IOverlayTransition;
60
- /** Defaults to the reverse of `enter`. */
60
+ /**
61
+ * Defaults to the presentation's default exit (see
62
+ * `DEFAULT_OVERLAY_ANIMATIONS`), or the reverse of `enter` when the
63
+ * presentation has no default exit.
64
+ */
61
65
  exit?: IOverlayTransition;
62
66
  /** Backdrop fade; runs on the same clock as the content by default. */
63
67
  backdrop?: { motion?: IOverlayMotionInput };
package/src/index.ts CHANGED
@@ -35,6 +35,7 @@ export {
35
35
  springToAndroidSpringForce,
36
36
  springToCssLinear,
37
37
  } from './animation/spring';
38
+ export { getAnchoredTransformOrigin } from './animation/anchoredOrigin';
38
39
  export { OverlayView } from './OverlayView';
39
40
  export {
40
41
  useEnclosingOverlayLevel,
@@ -1,3 +1,4 @@
1
+ import { getAnchoredTransformOrigin } from '../animation/anchoredOrigin';
1
2
  import { springToCssLinear } from '../animation/spring';
2
3
 
3
4
  import type { IResolvedOverlayTransition } from '../animation/resolveAnimation';
@@ -91,6 +92,45 @@ const VISIBLE_KEYFRAME: Keyframe = {
91
92
  transform: 'translate3d(0, 0, 0) scale(1)',
92
93
  };
93
94
 
95
+ export interface ITransitionKeyframeInput {
96
+ transition: IResolvedOverlayTransition;
97
+ extent: IContentExtent;
98
+ direction: 'in' | 'out';
99
+ /** Rendered frames of an interrupted run; the new run starts from them. */
100
+ sampled?: Keyframe;
101
+ }
102
+
103
+ /**
104
+ * Keyframes for one enter/exit run. Pure so the interruption rules can be
105
+ * tested without a DOM.
106
+ */
107
+ export function buildTransitionKeyframes({
108
+ transition,
109
+ extent,
110
+ direction,
111
+ sampled,
112
+ }: ITransitionKeyframeInput): [Keyframe, Keyframe] {
113
+ const hidden = hiddenKeyframe(transition, extent);
114
+ const visible: Keyframe = {};
115
+ Object.keys(hidden).forEach((key) => {
116
+ visible[key] = VISIBLE_KEYFRAME[key];
117
+ });
118
+ const initial = direction === 'in' ? hidden : visible;
119
+ const start: Keyframe = {};
120
+ Object.keys(initial).forEach((key) => {
121
+ start[key] = sampled?.[key] ?? initial[key];
122
+ });
123
+ const end: Keyframe = direction === 'in' ? visible : hidden;
124
+ // A fade-free exit does not animate opacity. Drop a partly transparent frame
125
+ // left by an interrupted fade-in so the card stays opaque while it scales out
126
+ // (OK-66647).
127
+ if (direction === 'out' && hidden.opacity === undefined) {
128
+ start.opacity = 1;
129
+ end.opacity = 1;
130
+ }
131
+ return [start, end];
132
+ }
133
+
94
134
  /**
95
135
  * Runs an enter (`direction: 'in'`) or exit transition on `element`. The
96
136
  * slide distance and scale origin come from the children of `contentRoot`,
@@ -120,21 +160,21 @@ export function animateTransition(
120
160
  anchoredContent instanceof HTMLElement ? anchoredContent : element;
121
161
  const targetRect =
122
162
  target === element ? undefined : target.getBoundingClientRect();
123
- target.style.transformOrigin = `${
124
- (extent.left + extent.right) / 2 - (targetRect?.left ?? 0)
125
- }px ${(extent.top + extent.bottom) / 2 - (targetRect?.top ?? 0)}px`;
126
- const hidden = hiddenKeyframe(effective, extent);
127
- const visible: Keyframe = {};
128
- Object.keys(hidden).forEach((key) => {
129
- visible[key] = VISIBLE_KEYFRAME[key];
130
- });
131
- const sampled = interruptedFrames?.get(target);
132
- const initial = direction === 'in' ? hidden : visible;
133
- const start: Keyframe = {};
134
- Object.keys(initial).forEach((key) => {
135
- start[key] = sampled?.[key] ?? initial[key];
163
+ const anchorOrigin =
164
+ target === element
165
+ ? undefined
166
+ : getAnchoredTransformOrigin(target.dataset.placement);
167
+ target.style.transformOrigin =
168
+ anchorOrigin ??
169
+ `${(extent.left + extent.right) / 2 - (targetRect?.left ?? 0)}px ${
170
+ (extent.top + extent.bottom) / 2 - (targetRect?.top ?? 0)
171
+ }px`;
172
+ const keyframes = buildTransitionKeyframes({
173
+ transition: effective,
174
+ extent,
175
+ direction,
176
+ sampled: interruptedFrames?.get(target),
136
177
  });
137
- const keyframes = [start, direction === 'in' ? visible : hidden];
138
178
  return target.animate(keyframes, {
139
179
  ...toTiming(effective.motion),
140
180
  fill: 'forwards',