@akylas/nativescript 9.0.25 → 9.1.5

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 (633) hide show
  1. package/abortcontroller/abortsignal.js.map +1 -1
  2. package/abortcontroller/index.js.map +1 -1
  3. package/accessibility/accessibility-common.js.map +1 -1
  4. package/accessibility/accessibility-css-helper.js.map +1 -1
  5. package/accessibility/accessibility-properties.js.map +1 -1
  6. package/accessibility/accessibility-service-common.js.map +1 -1
  7. package/accessibility/accessibility-service.android.js.map +1 -1
  8. package/accessibility/accessibility-service.ios.js.map +1 -1
  9. package/accessibility/accessibility-types.js.map +1 -1
  10. package/accessibility/font-scale-common.js.map +1 -1
  11. package/accessibility/font-scale.android.js.map +1 -1
  12. package/accessibility/font-scale.ios.js.map +1 -1
  13. package/accessibility/index.android.js.map +1 -1
  14. package/accessibility/index.ios.js.map +1 -1
  15. package/animation-frame/animation-native.android.js.map +1 -1
  16. package/animation-frame/animation-native.ios.js.map +1 -1
  17. package/animation-frame/index.js.map +1 -1
  18. package/application/application-common.d.ts +205 -3
  19. package/application/application-common.js +438 -55
  20. package/application/application-common.js.map +1 -1
  21. package/application/application-interfaces.d.ts +67 -1
  22. package/application/application-interfaces.js.map +1 -1
  23. package/application/application-shims.js.map +1 -1
  24. package/application/application.android.d.ts +39 -0
  25. package/application/application.android.js +239 -18
  26. package/application/application.android.js.map +1 -1
  27. package/application/application.d.ts +161 -54
  28. package/application/application.ios.d.ts +189 -28
  29. package/application/application.ios.js +892 -390
  30. package/application/application.ios.js.map +1 -1
  31. package/application/helpers-common.d.ts +7 -0
  32. package/application/helpers-common.js +46 -1
  33. package/application/helpers-common.js.map +1 -1
  34. package/application/helpers.android.js.map +1 -1
  35. package/application/helpers.ios.js.map +1 -1
  36. package/application/index.android.js.map +1 -1
  37. package/application/index.ios.js.map +1 -1
  38. package/application/scene-delegate-bridge.d.ts +60 -0
  39. package/application/scene-delegate-bridge.js +138 -0
  40. package/application/scene-delegate-bridge.js.map +1 -0
  41. package/application-settings/application-settings-common.js.map +1 -1
  42. package/application-settings/index.android.js.map +1 -1
  43. package/application-settings/index.ios.js.map +1 -1
  44. package/bundle-entry-points.js.map +1 -1
  45. package/cli-hooks/before-checkForChanges.mjs +0 -11
  46. package/color/color-common.js +16 -5
  47. package/color/color-common.js.map +1 -1
  48. package/color/color-types.js.map +1 -1
  49. package/color/color-utils.d.ts +4 -1
  50. package/color/color-utils.js +14 -9
  51. package/color/color-utils.js.map +1 -1
  52. package/color/index.android.js.map +1 -1
  53. package/color/index.ios.js.map +1 -1
  54. package/color/known-colors.js.map +1 -1
  55. package/config/config.interface.d.ts +45 -3
  56. package/config/config.interface.js.map +1 -1
  57. package/config/index.js.map +1 -1
  58. package/connectivity/index.android.js.map +1 -1
  59. package/connectivity/index.ios.js.map +1 -1
  60. package/console/index.js.map +1 -1
  61. package/core-types/animation-types.js.map +1 -1
  62. package/core-types/index.d.ts +25 -2
  63. package/core-types/index.js +23 -0
  64. package/core-types/index.js.map +1 -1
  65. package/core-types/validators.js.map +1 -1
  66. package/css/CSS3Parser.js +3 -2
  67. package/css/CSS3Parser.js.map +1 -1
  68. package/css/CSSNativeScript.js.map +1 -1
  69. package/css/css-tree-parser.js +5 -1
  70. package/css/css-tree-parser.js.map +1 -1
  71. package/css/lib/parse/index.js +5 -1
  72. package/css/lib/parse/index.js.map +1 -1
  73. package/css/parser.js +20 -3
  74. package/css/parser.js.map +1 -1
  75. package/css/reworkcss.js.map +1 -1
  76. package/css/system-classes.d.ts +9 -0
  77. package/css/system-classes.js +23 -0
  78. package/css/system-classes.js.map +1 -1
  79. package/css-mediaquery/index.d.ts +6 -1
  80. package/css-mediaquery/index.js +35 -6
  81. package/css-mediaquery/index.js.map +1 -1
  82. package/css-value/reworkcss-value.js.map +1 -1
  83. package/data/observable/index.d.ts +23 -0
  84. package/data/observable/index.js +50 -9
  85. package/data/observable/index.js.map +1 -1
  86. package/data/observable-array/index.js.map +1 -1
  87. package/data/virtual-array/index.js.map +1 -1
  88. package/debugger/InspectorBackendCommands.js.map +1 -1
  89. package/debugger/devtools-elements-interfaces.js.map +1 -1
  90. package/debugger/devtools-elements.common.js.map +1 -1
  91. package/debugger/devtools-elements.js.map +1 -1
  92. package/debugger/dom-types.js +31 -1
  93. package/debugger/dom-types.js.map +1 -1
  94. package/debugger/index.js.map +1 -1
  95. package/debugger/webinspector-css.js.map +1 -1
  96. package/debugger/webinspector-dom.js.map +1 -1
  97. package/debugger/webinspector-network.android.js.map +1 -1
  98. package/debugger/webinspector-network.d.ts +29 -0
  99. package/debugger/webinspector-network.ios.js.map +1 -1
  100. package/fetch/index.d.ts +79 -0
  101. package/fetch/index.js +408 -0
  102. package/fetch/index.js.map +1 -0
  103. package/file-system/file-system-access.android.d.ts +1 -0
  104. package/file-system/file-system-access.android.js +18 -21
  105. package/file-system/file-system-access.android.js.map +1 -1
  106. package/file-system/file-system-access.ios.js +21 -13
  107. package/file-system/file-system-access.ios.js.map +1 -1
  108. package/file-system/index.d.ts +3 -3
  109. package/file-system/index.js.map +1 -1
  110. package/fps-meter/fps-native.android.js.map +1 -1
  111. package/fps-meter/fps-native.ios.js.map +1 -1
  112. package/fps-meter/index.js.map +1 -1
  113. package/global-types.d.ts +40 -34
  114. package/globals/global-utils.d.ts +6 -1
  115. package/globals/global-utils.js +10 -5
  116. package/globals/global-utils.js.map +1 -1
  117. package/globals/index.js +22 -9
  118. package/globals/index.js.map +1 -1
  119. package/globals/polyfills/polyfill-xhr.js.map +1 -1
  120. package/globals/polyfills/utils.js +2 -0
  121. package/globals/polyfills/utils.js.map +1 -1
  122. package/http/http-interfaces.js.map +1 -1
  123. package/http/http-request/http-request-common.js.map +1 -1
  124. package/http/http-request/index.android.js +5 -1
  125. package/http/http-request/index.android.js.map +1 -1
  126. package/http/http-request/index.ios.js.map +1 -1
  127. package/http/http-request-internal/http-request-internal-common.d.ts +6 -1
  128. package/http/http-request-internal/http-request-internal-common.js +19 -0
  129. package/http/http-request-internal/http-request-internal-common.js.map +1 -1
  130. package/http/http-request-internal/index.android.d.ts +7 -1
  131. package/http/http-request-internal/index.android.js +8 -6
  132. package/http/http-request-internal/index.android.js.map +1 -1
  133. package/http/http-request-internal/index.ios.d.ts +7 -1
  134. package/http/http-request-internal/index.ios.js +34 -17
  135. package/http/http-request-internal/index.ios.js.map +1 -1
  136. package/http/index.js.map +1 -1
  137. package/image-asset/image-asset-common.js.map +1 -1
  138. package/image-asset/index.android.js.map +1 -1
  139. package/image-asset/index.ios.js.map +1 -1
  140. package/image-source/image-source-common.js.map +1 -1
  141. package/image-source/index.android.js.map +1 -1
  142. package/image-source/index.ios.js +7 -6
  143. package/image-source/index.ios.js.map +1 -1
  144. package/index.d.ts +3 -1
  145. package/index.js +1 -0
  146. package/index.js.map +1 -1
  147. package/inspector_modules.js +1 -1
  148. package/inspector_modules.js.map +1 -1
  149. package/js-libs/easysax/easysax.d.ts +49 -7
  150. package/js-libs/easysax/easysax.js +631 -747
  151. package/js-libs/easysax/easysax.js.map +1 -0
  152. package/matrix/index.js.map +1 -1
  153. package/media-query-list/index.js +57 -15
  154. package/media-query-list/index.js.map +1 -1
  155. package/module-name-resolver/helpers.d.ts +1 -1
  156. package/module-name-resolver/helpers.js.map +1 -1
  157. package/module-name-resolver/index.d.ts +2 -2
  158. package/module-name-resolver/index.js.map +1 -1
  159. package/module-name-resolver/non-bundle-workflow-compat.js.map +1 -1
  160. package/module-name-resolver/qualifier-matcher/index.js.map +1 -1
  161. package/native-window/index.d.ts +426 -0
  162. package/native-window/index.js +4 -0
  163. package/native-window/index.js.map +1 -0
  164. package/native-window/native-window-common.d.ts +153 -0
  165. package/native-window/native-window-common.js +340 -0
  166. package/native-window/native-window-common.js.map +1 -0
  167. package/native-window/native-window-interfaces.d.ts +186 -0
  168. package/native-window/native-window-interfaces.js +90 -0
  169. package/native-window/native-window-interfaces.js.map +1 -0
  170. package/native-window/native-window.android.d.ts +59 -0
  171. package/native-window/native-window.android.js +175 -0
  172. package/native-window/native-window.android.js.map +1 -0
  173. package/native-window/native-window.ios.d.ts +61 -0
  174. package/native-window/native-window.ios.js +218 -0
  175. package/native-window/native-window.ios.js.map +1 -0
  176. package/native-window/window-base.d.ts +111 -0
  177. package/native-window/window-base.js +91 -0
  178. package/native-window/window-base.js.map +1 -0
  179. package/package.json +3 -3
  180. package/platform/common.js.map +1 -1
  181. package/platform/device/index.android.js.map +1 -1
  182. package/platform/device/index.ios.js.map +1 -1
  183. package/platform/index.js.map +1 -1
  184. package/platform/screen/index.android.js.map +1 -1
  185. package/platform/screen/index.ios.d.ts +1 -0
  186. package/platform/screen/index.ios.js +6 -2
  187. package/platform/screen/index.ios.js.map +1 -1
  188. package/platforms/android/java/org/nativescript/widgets/BorderDrawable.java +5 -6
  189. package/platforms/android/java/org/nativescript/widgets/BoxShadowDrawable.java +0 -6
  190. package/platforms/android/java/org/nativescript/widgets/CommonLayoutParams.java +56 -0
  191. package/platforms/android/java/org/nativescript/widgets/ContentLayout.java +20 -4
  192. package/platforms/android/java/org/nativescript/widgets/CustomTransition.java +26 -9
  193. package/platforms/android/java/org/nativescript/widgets/FlexLine.java +3 -3
  194. package/platforms/android/java/org/nativescript/widgets/FlexboxLayout.java +194 -731
  195. package/platforms/android/java/org/nativescript/widgets/ImageView.java +2 -2
  196. package/platforms/android/java/org/nativescript/widgets/Utils.java +37 -9
  197. package/platforms/android/java/org/nativescript/widgets/ViewHelper.java +78 -0
  198. package/platforms/android/java/org/nativescript/widgets/image/BitmapOwner.java +1 -4
  199. package/platforms/android/java/org/nativescript/widgets/image/Worker.java +99 -76
  200. package/platforms/android/native-api-usage.json +11 -0
  201. package/platforms/ios/src/NativeScriptMainWindow.swift +72 -39
  202. package/profiling/index.js.map +1 -1
  203. package/references.d.ts +5 -2
  204. package/text/formatted-string.js.map +1 -1
  205. package/text/index.android.js.map +1 -1
  206. package/text/index.ios.js.map +1 -1
  207. package/text/span.js.map +1 -1
  208. package/text/text-common.js +1 -1
  209. package/text/text-common.js.map +1 -1
  210. package/timer/index.android.js +2 -1
  211. package/timer/index.android.js.map +1 -1
  212. package/timer/index.ios.js.map +1 -1
  213. package/trace/index.d.ts +2 -2
  214. package/trace/index.js.map +1 -1
  215. package/ui/action-bar/action-bar-common.js.map +1 -1
  216. package/ui/action-bar/index.android.js +7 -11
  217. package/ui/action-bar/index.android.js.map +1 -1
  218. package/ui/action-bar/index.d.ts +13 -1
  219. package/ui/action-bar/index.ios.js +26 -0
  220. package/ui/action-bar/index.ios.js.map +1 -1
  221. package/ui/activity-indicator/activity-indicator-common.js.map +1 -1
  222. package/ui/activity-indicator/index.android.js.map +1 -1
  223. package/ui/activity-indicator/index.ios.js.map +1 -1
  224. package/ui/animation/animation-common.js.map +1 -1
  225. package/ui/animation/animation-interfaces.js.map +1 -1
  226. package/ui/animation/animation-shared.js.map +1 -1
  227. package/ui/animation/animation-types.js.map +1 -1
  228. package/ui/animation/index.android.js.map +1 -1
  229. package/ui/animation/index.ios.js +6 -1
  230. package/ui/animation/index.ios.js.map +1 -1
  231. package/ui/animation/keyframe-animation.d.ts +3 -1
  232. package/ui/animation/keyframe-animation.js +72 -3
  233. package/ui/animation/keyframe-animation.js.map +1 -1
  234. package/ui/builder/binding-builder.d.ts +8 -0
  235. package/ui/builder/binding-builder.js +12 -0
  236. package/ui/builder/binding-builder.js.map +1 -1
  237. package/ui/builder/component-builder/index.d.ts +7 -4
  238. package/ui/builder/component-builder/index.js +13 -7
  239. package/ui/builder/component-builder/index.js.map +1 -1
  240. package/ui/builder/index.d.ts +16 -2
  241. package/ui/builder/index.js +61 -13
  242. package/ui/builder/index.js.map +1 -1
  243. package/ui/button/button-common.js.map +1 -1
  244. package/ui/button/index.android.js +4 -3
  245. package/ui/button/index.android.js.map +1 -1
  246. package/ui/button/index.ios.js.map +1 -1
  247. package/ui/content-view/index.js +2 -0
  248. package/ui/content-view/index.js.map +1 -1
  249. package/ui/core/bindable/bindable-expressions.js.map +1 -1
  250. package/ui/core/bindable/bindable-resources.js.map +1 -1
  251. package/ui/core/bindable/bindable-types.d.ts +15 -0
  252. package/ui/core/bindable/bindable-types.js.map +1 -1
  253. package/ui/core/bindable/index.d.ts +1 -1
  254. package/ui/core/bindable/index.js +14 -8
  255. package/ui/core/bindable/index.js.map +1 -1
  256. package/ui/core/control-state-change/index.android.js.map +1 -1
  257. package/ui/core/control-state-change/index.ios.js.map +1 -1
  258. package/ui/core/properties/index.d.ts +37 -2
  259. package/ui/core/properties/index.js +205 -29
  260. package/ui/core/properties/index.js.map +1 -1
  261. package/ui/core/properties/property-shared.js +11 -2
  262. package/ui/core/properties/property-shared.js.map +1 -1
  263. package/ui/core/view/index.android.d.ts +5 -0
  264. package/ui/core/view/index.android.js +89 -15
  265. package/ui/core/view/index.android.js.map +1 -1
  266. package/ui/core/view/index.d.ts +58 -1
  267. package/ui/core/view/index.ios.d.ts +1 -0
  268. package/ui/core/view/index.ios.js +48 -11
  269. package/ui/core/view/index.ios.js.map +1 -1
  270. package/ui/core/view/view-common.d.ts +37 -0
  271. package/ui/core/view/view-common.js +81 -0
  272. package/ui/core/view/view-common.js.map +1 -1
  273. package/ui/core/view/view-helper/index.android.d.ts +1 -0
  274. package/ui/core/view/view-helper/index.android.js +8 -0
  275. package/ui/core/view/view-helper/index.android.js.map +1 -1
  276. package/ui/core/view/view-helper/index.d.ts +46 -0
  277. package/ui/core/view/view-helper/index.ios.d.ts +42 -0
  278. package/ui/core/view/view-helper/index.ios.js +170 -5
  279. package/ui/core/view/view-helper/index.ios.js.map +1 -1
  280. package/ui/core/view/view-helper/view-helper-common.js +21 -3
  281. package/ui/core/view/view-helper/view-helper-common.js.map +1 -1
  282. package/ui/core/view/view-helper/view-helper-shared.js.map +1 -1
  283. package/ui/core/view/view-interfaces.js.map +1 -1
  284. package/ui/core/view-base/index.js +75 -36
  285. package/ui/core/view-base/index.js.map +1 -1
  286. package/ui/core/view-base/utils.js.map +1 -1
  287. package/ui/core/weak-event-listener/index.js.map +1 -1
  288. package/ui/date-picker/date-picker-common.js.map +1 -1
  289. package/ui/date-picker/index.android.js +1 -1
  290. package/ui/date-picker/index.android.js.map +1 -1
  291. package/ui/date-picker/index.ios.js.map +1 -1
  292. package/ui/dialogs/dialogs-common.js.map +1 -1
  293. package/ui/dialogs/index.android.js +5 -5
  294. package/ui/dialogs/index.android.js.map +1 -1
  295. package/ui/dialogs/index.ios.js.map +1 -1
  296. package/ui/editable-text-base/editable-text-base-common.js.map +1 -1
  297. package/ui/editable-text-base/index.android.d.ts +2 -0
  298. package/ui/editable-text-base/index.android.js +17 -7
  299. package/ui/editable-text-base/index.android.js.map +1 -1
  300. package/ui/editable-text-base/index.d.ts +8 -0
  301. package/ui/editable-text-base/index.ios.js.map +1 -1
  302. package/ui/embedding/index.android.js.map +1 -1
  303. package/ui/embedding/index.ios.js.map +1 -1
  304. package/ui/enums/enums.js.map +1 -1
  305. package/ui/enums/index.js.map +1 -1
  306. package/ui/frame/activity.android.js.map +1 -1
  307. package/ui/frame/fragment.android.js.map +1 -1
  308. package/ui/frame/fragment.ios.js.map +1 -1
  309. package/ui/frame/fragment.transitions.android.d.ts +12 -9
  310. package/ui/frame/fragment.transitions.android.js +105 -90
  311. package/ui/frame/fragment.transitions.android.js.map +1 -1
  312. package/ui/frame/fragment.transitions.types.js.map +1 -1
  313. package/ui/frame/frame-common.d.ts +14 -2
  314. package/ui/frame/frame-common.js +51 -24
  315. package/ui/frame/frame-common.js.map +1 -1
  316. package/ui/frame/frame-constants.d.ts +9 -0
  317. package/ui/frame/frame-constants.js +10 -0
  318. package/ui/frame/frame-constants.js.map +1 -0
  319. package/ui/frame/frame-helper-for-android.d.ts +2 -2
  320. package/ui/frame/frame-helper-for-android.js +14 -5
  321. package/ui/frame/frame-helper-for-android.js.map +1 -1
  322. package/ui/frame/frame-helpers.js.map +1 -1
  323. package/ui/frame/frame-interfaces.d.ts +1 -1
  324. package/ui/frame/frame-interfaces.js.map +1 -1
  325. package/ui/frame/frame-stack.d.ts +22 -1
  326. package/ui/frame/frame-stack.js +43 -5
  327. package/ui/frame/frame-stack.js.map +1 -1
  328. package/ui/frame/index.android.d.ts +2 -2
  329. package/ui/frame/index.android.js +161 -56
  330. package/ui/frame/index.android.js.map +1 -1
  331. package/ui/frame/index.d.ts +15 -5
  332. package/ui/frame/index.ios.d.ts +1 -1
  333. package/ui/frame/index.ios.js +86 -26
  334. package/ui/frame/index.ios.js.map +1 -1
  335. package/ui/gestures/gestures-common.js.map +1 -1
  336. package/ui/gestures/gestures-types.d.ts +2 -0
  337. package/ui/gestures/gestures-types.js.map +1 -1
  338. package/ui/gestures/index.android.d.ts +1 -1
  339. package/ui/gestures/index.android.js +177 -133
  340. package/ui/gestures/index.android.js.map +1 -1
  341. package/ui/gestures/index.ios.js +36 -7
  342. package/ui/gestures/index.ios.js.map +1 -1
  343. package/ui/gestures/touch-manager.d.ts +1 -2
  344. package/ui/gestures/touch-manager.js +79 -50
  345. package/ui/gestures/touch-manager.js.map +1 -1
  346. package/ui/html-view/html-view-common.js.map +1 -1
  347. package/ui/html-view/index.android.js.map +1 -1
  348. package/ui/html-view/index.ios.js.map +1 -1
  349. package/ui/image/image-common.js +1 -1
  350. package/ui/image/image-common.js.map +1 -1
  351. package/ui/image/index.android.js +14 -2
  352. package/ui/image/index.android.js.map +1 -1
  353. package/ui/image/index.ios.js.map +1 -1
  354. package/ui/image/symbol-effects-common.js.map +1 -1
  355. package/ui/image/symbol-effects.android.js.map +1 -1
  356. package/ui/image/symbol-effects.ios.js.map +1 -1
  357. package/ui/image-cache/image-cache-common.js.map +1 -1
  358. package/ui/image-cache/index.android.js +1 -2
  359. package/ui/image-cache/index.android.js.map +1 -1
  360. package/ui/image-cache/index.ios.js.map +1 -1
  361. package/ui/index.d.ts +2 -2
  362. package/ui/index.js.map +1 -1
  363. package/ui/label/index.android.js.map +1 -1
  364. package/ui/label/index.ios.js.map +1 -1
  365. package/ui/layouts/absolute-layout/absolute-layout-common.js.map +1 -1
  366. package/ui/layouts/absolute-layout/index.android.js.map +1 -1
  367. package/ui/layouts/absolute-layout/index.ios.js +3 -0
  368. package/ui/layouts/absolute-layout/index.ios.js.map +1 -1
  369. package/ui/layouts/dock-layout/dock-layout-common.js.map +1 -1
  370. package/ui/layouts/dock-layout/index.android.js.map +1 -1
  371. package/ui/layouts/dock-layout/index.ios.js +3 -0
  372. package/ui/layouts/dock-layout/index.ios.js.map +1 -1
  373. package/ui/layouts/flexbox-layout/flexbox-layout-common.d.ts +7 -0
  374. package/ui/layouts/flexbox-layout/flexbox-layout-common.js +18 -0
  375. package/ui/layouts/flexbox-layout/flexbox-layout-common.js.map +1 -1
  376. package/ui/layouts/flexbox-layout/index.android.d.ts +5 -0
  377. package/ui/layouts/flexbox-layout/index.android.js +15 -0
  378. package/ui/layouts/flexbox-layout/index.android.js.map +1 -1
  379. package/ui/layouts/flexbox-layout/index.d.ts +19 -1
  380. package/ui/layouts/flexbox-layout/index.ios.d.ts +2 -0
  381. package/ui/layouts/flexbox-layout/index.ios.js +246 -195
  382. package/ui/layouts/flexbox-layout/index.ios.js.map +1 -1
  383. package/ui/layouts/grid-layout/grid-layout-common.js.map +1 -1
  384. package/ui/layouts/grid-layout/index.android.js.map +1 -1
  385. package/ui/layouts/grid-layout/index.ios.js +3 -0
  386. package/ui/layouts/grid-layout/index.ios.js.map +1 -1
  387. package/ui/layouts/index.js.map +1 -1
  388. package/ui/layouts/layout-base-common.d.ts +1 -0
  389. package/ui/layouts/layout-base-common.js +23 -1
  390. package/ui/layouts/layout-base-common.js.map +1 -1
  391. package/ui/layouts/layout-base.android.js.map +1 -1
  392. package/ui/layouts/layout-base.ios.js.map +1 -1
  393. package/ui/layouts/liquid-glass/index.android.js.map +1 -1
  394. package/ui/layouts/liquid-glass/index.ios.d.ts +0 -1
  395. package/ui/layouts/liquid-glass/index.ios.js +2 -43
  396. package/ui/layouts/liquid-glass/index.ios.js.map +1 -1
  397. package/ui/layouts/liquid-glass/liquid-glass-common.js.map +1 -1
  398. package/ui/layouts/liquid-glass-container/index.android.js.map +1 -1
  399. package/ui/layouts/liquid-glass-container/index.ios.d.ts +0 -1
  400. package/ui/layouts/liquid-glass-container/index.ios.js +2 -43
  401. package/ui/layouts/liquid-glass-container/index.ios.js.map +1 -1
  402. package/ui/layouts/liquid-glass-container/liquid-glass-container-common.js.map +1 -1
  403. package/ui/layouts/root-layout/index.android.js.map +1 -1
  404. package/ui/layouts/root-layout/index.ios.js.map +1 -1
  405. package/ui/layouts/root-layout/root-layout-common.js.map +1 -1
  406. package/ui/layouts/root-layout/root-layout-stack.js.map +1 -1
  407. package/ui/layouts/stack-layout/index.android.js.map +1 -1
  408. package/ui/layouts/stack-layout/index.ios.js +3 -0
  409. package/ui/layouts/stack-layout/index.ios.js.map +1 -1
  410. package/ui/layouts/stack-layout/stack-layout-common.js.map +1 -1
  411. package/ui/layouts/wrap-layout/index.android.js.map +1 -1
  412. package/ui/layouts/wrap-layout/index.ios.js +3 -0
  413. package/ui/layouts/wrap-layout/index.ios.js.map +1 -1
  414. package/ui/layouts/wrap-layout/wrap-layout-common.js.map +1 -1
  415. package/ui/list-picker/index.android.d.ts +1 -0
  416. package/ui/list-picker/index.android.js +6 -5
  417. package/ui/list-picker/index.android.js.map +1 -1
  418. package/ui/list-picker/index.ios.js.map +1 -1
  419. package/ui/list-picker/list-picker-common.js.map +1 -1
  420. package/ui/list-view/index.android.js +19 -11
  421. package/ui/list-view/index.android.js.map +1 -1
  422. package/ui/list-view/index.d.ts +47 -3
  423. package/ui/list-view/index.ios.d.ts +13 -3
  424. package/ui/list-view/index.ios.js +132 -41
  425. package/ui/list-view/index.ios.js.map +1 -1
  426. package/ui/list-view/list-view-common.d.ts +19 -0
  427. package/ui/list-view/list-view-common.js +30 -0
  428. package/ui/list-view/list-view-common.js.map +1 -1
  429. package/ui/page/events.js.map +1 -1
  430. package/ui/page/index.android.js.map +1 -1
  431. package/ui/page/index.d.ts +1 -1
  432. package/ui/page/index.ios.d.ts +3 -1
  433. package/ui/page/index.ios.js +33 -20
  434. package/ui/page/index.ios.js.map +1 -1
  435. package/ui/page/page-common.d.ts +5 -1
  436. package/ui/page/page-common.js.map +1 -1
  437. package/ui/placeholder/index.android.js.map +1 -1
  438. package/ui/placeholder/index.js.map +1 -1
  439. package/ui/placeholder/placeholder-common.js.map +1 -1
  440. package/ui/progress/index.android.js.map +1 -1
  441. package/ui/progress/index.ios.js.map +1 -1
  442. package/ui/progress/progress-common.js.map +1 -1
  443. package/ui/proxy-view-container/index.js.map +1 -1
  444. package/ui/repeater/index.d.ts +2 -1
  445. package/ui/repeater/index.js.map +1 -1
  446. package/ui/scroll-view/index.android.d.ts +2 -1
  447. package/ui/scroll-view/index.android.js +4 -1
  448. package/ui/scroll-view/index.android.js.map +1 -1
  449. package/ui/scroll-view/index.d.ts +53 -0
  450. package/ui/scroll-view/index.ios.d.ts +13 -1
  451. package/ui/scroll-view/index.ios.js +100 -20
  452. package/ui/scroll-view/index.ios.js.map +1 -1
  453. package/ui/scroll-view/scroll-view-common.d.ts +13 -0
  454. package/ui/scroll-view/scroll-view-common.js +27 -0
  455. package/ui/scroll-view/scroll-view-common.js.map +1 -1
  456. package/ui/search-bar/index.android.js +2 -2
  457. package/ui/search-bar/index.android.js.map +1 -1
  458. package/ui/search-bar/index.ios.js.map +1 -1
  459. package/ui/search-bar/search-bar-common.js.map +1 -1
  460. package/ui/segmented-bar/index.android.js +8 -8
  461. package/ui/segmented-bar/index.android.js.map +1 -1
  462. package/ui/segmented-bar/index.ios.js.map +1 -1
  463. package/ui/segmented-bar/segmented-bar-common.d.ts +5 -1
  464. package/ui/segmented-bar/segmented-bar-common.js +6 -1
  465. package/ui/segmented-bar/segmented-bar-common.js.map +1 -1
  466. package/ui/slider/index.android.js +1 -2
  467. package/ui/slider/index.android.js.map +1 -1
  468. package/ui/slider/index.ios.js.map +1 -1
  469. package/ui/slider/slider-common.js.map +1 -1
  470. package/ui/split-view/index.android.js.map +1 -1
  471. package/ui/split-view/index.ios.js.map +1 -1
  472. package/ui/split-view/split-view-common.js.map +1 -1
  473. package/ui/styling/background-common.d.ts +2 -0
  474. package/ui/styling/background-common.js +10 -2
  475. package/ui/styling/background-common.js.map +1 -1
  476. package/ui/styling/background.android.d.ts +4 -1
  477. package/ui/styling/background.android.js +5 -2
  478. package/ui/styling/background.android.js.map +1 -1
  479. package/ui/styling/background.d.ts +2 -2
  480. package/ui/styling/background.ios.d.ts +1 -1
  481. package/ui/styling/background.ios.js +10 -3
  482. package/ui/styling/background.ios.js.map +1 -1
  483. package/ui/styling/box-shadow.js.map +1 -1
  484. package/ui/styling/clip-path-function.js.map +1 -1
  485. package/ui/styling/converters.js.map +1 -1
  486. package/ui/styling/css-animation-parser.js.map +1 -1
  487. package/ui/styling/css-selector.d.ts +60 -13
  488. package/ui/styling/css-selector.js +311 -50
  489. package/ui/styling/css-selector.js.map +1 -1
  490. package/ui/styling/css-shadow.js.map +1 -1
  491. package/ui/styling/css-stroke.js.map +1 -1
  492. package/ui/styling/css-transform.js.map +1 -1
  493. package/ui/styling/css-utils.d.ts +16 -0
  494. package/ui/styling/css-utils.js +121 -7
  495. package/ui/styling/css-utils.js.map +1 -1
  496. package/ui/styling/font-common.js.map +1 -1
  497. package/ui/styling/font-interfaces.js.map +1 -1
  498. package/ui/styling/font.android.js.map +1 -1
  499. package/ui/styling/font.ios.js.map +1 -1
  500. package/ui/styling/length-shared.d.ts +2 -0
  501. package/ui/styling/length-shared.js +29 -2
  502. package/ui/styling/length-shared.js.map +1 -1
  503. package/ui/styling/linear-gradient.js.map +1 -1
  504. package/ui/styling/style/index.d.ts +29 -2
  505. package/ui/styling/style/index.js +1 -0
  506. package/ui/styling/style/index.js.map +1 -1
  507. package/ui/styling/style-properties.d.ts +5 -0
  508. package/ui/styling/style-properties.js +172 -101
  509. package/ui/styling/style-properties.js.map +1 -1
  510. package/ui/styling/style-scope.d.ts +24 -3
  511. package/ui/styling/style-scope.js +461 -63
  512. package/ui/styling/style-scope.js.map +1 -1
  513. package/ui/styling/styling-profile.js.map +1 -1
  514. package/ui/styling/styling-shared.js.map +1 -1
  515. package/ui/switch/index.android.js +1 -1
  516. package/ui/switch/index.android.js.map +1 -1
  517. package/ui/switch/index.ios.js +5 -1
  518. package/ui/switch/index.ios.js.map +1 -1
  519. package/ui/switch/switch-common.js.map +1 -1
  520. package/ui/tab-view/index.android.js +13 -17
  521. package/ui/tab-view/index.android.js.map +1 -1
  522. package/ui/tab-view/index.d.ts +5 -3
  523. package/ui/tab-view/index.ios.d.ts +2 -1
  524. package/ui/tab-view/index.ios.js +83 -20
  525. package/ui/tab-view/index.ios.js.map +1 -1
  526. package/ui/tab-view/tab-view-common.d.ts +6 -1
  527. package/ui/tab-view/tab-view-common.js +17 -1
  528. package/ui/tab-view/tab-view-common.js.map +1 -1
  529. package/ui/text-base/formatted-string.js.map +1 -1
  530. package/ui/text-base/index.android.js +6 -9
  531. package/ui/text-base/index.android.js.map +1 -1
  532. package/ui/text-base/index.ios.d.ts +3 -0
  533. package/ui/text-base/index.ios.js +26 -4
  534. package/ui/text-base/index.ios.js.map +1 -1
  535. package/ui/text-base/span.js.map +1 -1
  536. package/ui/text-base/text-base-common.js.map +1 -1
  537. package/ui/text-field/index.android.js.map +1 -1
  538. package/ui/text-field/index.ios.js +13 -5
  539. package/ui/text-field/index.ios.js.map +1 -1
  540. package/ui/text-field/text-field-common.js.map +1 -1
  541. package/ui/text-view/index.android.js.map +1 -1
  542. package/ui/text-view/index.ios.js.map +1 -1
  543. package/ui/text-view/text-view-common.js.map +1 -1
  544. package/ui/time-picker/index.android.js +1 -1
  545. package/ui/time-picker/index.android.js.map +1 -1
  546. package/ui/time-picker/index.ios.js.map +1 -1
  547. package/ui/time-picker/time-picker-common.js.map +1 -1
  548. package/ui/transition/fade-transition.android.js.map +1 -1
  549. package/ui/transition/fade-transition.ios.js.map +1 -1
  550. package/ui/transition/flip-transition.android.js.map +1 -1
  551. package/ui/transition/index.android.js.map +1 -1
  552. package/ui/transition/index.d.ts +2 -1
  553. package/ui/transition/index.ios.js.map +1 -1
  554. package/ui/transition/modal-transition.android.js.map +1 -1
  555. package/ui/transition/modal-transition.ios.js +33 -5
  556. package/ui/transition/modal-transition.ios.js.map +1 -1
  557. package/ui/transition/page-transition.android.d.ts +4 -0
  558. package/ui/transition/page-transition.android.js +171 -86
  559. package/ui/transition/page-transition.android.js.map +1 -1
  560. package/ui/transition/page-transition.ios.d.ts +5 -0
  561. package/ui/transition/page-transition.ios.js +298 -36
  562. package/ui/transition/page-transition.ios.js.map +1 -1
  563. package/ui/transition/shared-transition-helper.android.d.ts +3 -0
  564. package/ui/transition/shared-transition-helper.android.js +9 -0
  565. package/ui/transition/shared-transition-helper.android.js.map +1 -1
  566. package/ui/transition/shared-transition-helper.d.ts +7 -0
  567. package/ui/transition/shared-transition-helper.ios.d.ts +48 -0
  568. package/ui/transition/shared-transition-helper.ios.js +977 -95
  569. package/ui/transition/shared-transition-helper.ios.js.map +1 -1
  570. package/ui/transition/shared-transition.d.ts +134 -0
  571. package/ui/transition/shared-transition.js +90 -2
  572. package/ui/transition/shared-transition.js.map +1 -1
  573. package/ui/transition/slide-transition.android.js.map +1 -1
  574. package/ui/transition/slide-transition.ios.js.map +1 -1
  575. package/ui/utils.android.js.map +1 -1
  576. package/ui/utils.d.ts +2 -0
  577. package/ui/utils.ios.js.map +1 -1
  578. package/ui/web-view/index.android.js +1 -1
  579. package/ui/web-view/index.android.js.map +1 -1
  580. package/ui/web-view/index.ios.js.map +1 -1
  581. package/ui/web-view/web-view-common.js.map +1 -1
  582. package/ui/web-view/web-view-interfaces.js.map +1 -1
  583. package/utils/android-runtime-version.d.ts +12 -0
  584. package/utils/android-runtime-version.js +36 -0
  585. package/utils/android-runtime-version.js.map +1 -0
  586. package/utils/animation-helpers.js.map +1 -1
  587. package/utils/common.js.map +1 -1
  588. package/utils/constants.android.js.map +1 -1
  589. package/utils/constants.ios.js.map +1 -1
  590. package/utils/debug-source.js.map +1 -1
  591. package/utils/debug.js.map +1 -1
  592. package/utils/index.android.js.map +1 -1
  593. package/utils/index.ios.js.map +1 -1
  594. package/utils/layout-helper/index.android.js.map +1 -1
  595. package/utils/layout-helper/index.ios.js +11 -3
  596. package/utils/layout-helper/index.ios.js.map +1 -1
  597. package/utils/layout-helper/layout-helper-common.js.map +1 -1
  598. package/utils/layout-helper/layout-helper-shared.js.map +1 -1
  599. package/utils/lazy.js.map +1 -1
  600. package/utils/macrotask-scheduler.js.map +1 -1
  601. package/utils/mainthread-helper.android.js.map +1 -1
  602. package/utils/mainthread-helper.ios.js.map +1 -1
  603. package/utils/module-merge.js.map +1 -1
  604. package/utils/native-helper-for-android.js +9 -3
  605. package/utils/native-helper-for-android.js.map +1 -1
  606. package/utils/native-helper.android.d.ts +66 -2
  607. package/utils/native-helper.android.js.map +1 -1
  608. package/utils/native-helper.d.ts +2 -2
  609. package/utils/native-helper.ios.d.ts +52 -2
  610. package/utils/native-helper.ios.js +35 -5
  611. package/utils/native-helper.ios.js.map +1 -1
  612. package/utils/native-helper.types.d.ts +2 -0
  613. package/utils/number-utils.js.map +1 -1
  614. package/utils/platform-check.d.ts +1 -1
  615. package/utils/platform-check.js.map +1 -1
  616. package/utils/shared.js.map +1 -1
  617. package/utils/types.js.map +1 -1
  618. package/utils/utils-shared.js.map +1 -1
  619. package/wgc/atob.js.map +1 -1
  620. package/wgc/btoa.js.map +1 -1
  621. package/wgc/crypto/SubtleCrypto.js.map +1 -1
  622. package/wgc/crypto/index.d.ts +1 -1
  623. package/wgc/crypto/index.js +12 -8
  624. package/wgc/crypto/index.js.map +1 -1
  625. package/wgc/index.js.map +1 -1
  626. package/xhr/index.d.ts +5 -4
  627. package/xhr/index.js +18 -18
  628. package/xhr/index.js.map +1 -1
  629. package/xml/index.d.ts +2 -2
  630. package/xml/index.js +1 -1
  631. package/xml/index.js.map +1 -1
  632. package/LICENSE +0 -19
  633. package/fetch/index.mjs +0 -535
@@ -3,13 +3,162 @@ import { isNumber } from '../../utils/types';
3
3
  import { Screen } from '../../platform';
4
4
  import { CORE_ANIMATION_DEFAULTS } from '../../utils/animation-helpers';
5
5
  import { ios as iOSUtils } from '../../utils/native-helper';
6
+ import { Color } from '../../color';
7
+ import { Trace } from '../../trace';
8
+ function getControllerPage(controller) {
9
+ return controller?.['_entry']?.resolvedPage ?? controller?._owner?.deref?.() ?? controller?.owner?.deref?.() ?? null;
10
+ }
11
+ /**
12
+ * Frame, in the container coordinates, of what the view really shows.
13
+ * An aspect fit image view has letterbox around its image: animating its bounds would stretch the image
14
+ * and make it jump to the right size at the end of the transition.
15
+ * Aspect fill (cropped) and non image views simply use their bounds.
16
+ */
17
+ function getDisplayedFrame(view, container) {
18
+ let rect = view.bounds;
19
+ if (view instanceof UIImageView && view.image && view.contentMode === 1 /* UIViewContentMode.ScaleAspectFit */) {
20
+ const imageSize = view.image.size;
21
+ if (imageSize.width > 0 && imageSize.height > 0 && rect.size.width > 0 && rect.size.height > 0) {
22
+ const scale = Math.min(rect.size.width / imageSize.width, rect.size.height / imageSize.height);
23
+ const width = imageSize.width * scale;
24
+ const height = imageSize.height * scale;
25
+ rect = CGRectMake(rect.origin.x + (rect.size.width - width) / 2, rect.origin.y + (rect.size.height - height) / 2, width, height);
26
+ }
27
+ }
28
+ return view.convertRectToView(rect, container);
29
+ }
30
+ // when both sides are images, the snapshot is filled like the source one: both ends then show the exact same pixels
31
+ // (the end frame of an aspect fit image has the aspect ratio of the image)
32
+ function getSnapshotContentMode(from, to) {
33
+ return from instanceof UIImageView ? from.contentMode : to.contentMode;
34
+ }
35
+ /**
36
+ * Apply a drop shadow behind the destination view during an interactive
37
+ * dismiss so it looks elevated above the source (Apple Music–style).
38
+ *
39
+ * Shadow + rounded corners can't coexist on the same CALayer on iOS — both
40
+ * `masksToBounds = true` and `layer.mask` clip the shadow as part of the
41
+ * compositing pipeline. So the shadow lives on a SIBLING CALayer inserted
42
+ * below the modal's layer in its superlayer (the same pattern NS uses for
43
+ * box-shadow via `outerShadowContainerLayer`). The modal keeps its own
44
+ * `cornerRadius` + `masksToBounds` so subviews still clip to the rounded
45
+ * shape.
46
+ *
47
+ * Because the shadow layer is a sibling (not a child), it doesn't inherit
48
+ * the modal's transform automatically — `syncInteractiveDismissShadow`
49
+ * mirrors transform/position/bounds during the drag.
50
+ *
51
+ * Falsy `shadowConfig` is a no-op.
52
+ */
53
+ export function applyInteractiveDismissShadow(presentedView, shadowConfig) {
54
+ if (!presentedView?.layer || !shadowConfig)
55
+ return;
56
+ const layer = presentedView.layer;
57
+ const superlayer = layer.superlayer;
58
+ if (!superlayer)
59
+ return;
60
+ const bounds = layer.bounds;
61
+ if (bounds.size.width <= 0 || bounds.size.height <= 0)
62
+ return;
63
+ // Idempotent.
64
+ if (presentedView.__sharedTransitionShadowLayer)
65
+ return;
66
+ const cfg = shadowConfig === true ? {} : shadowConfig;
67
+ const colorInput = cfg.color ?? '#000';
68
+ let cgColor;
69
+ try {
70
+ const nsColor = typeof colorInput === 'string' ? new Color(colorInput) : colorInput;
71
+ cgColor = nsColor.ios?.CGColor || nsColor.CGColor || UIColor.blackColor.CGColor;
72
+ }
73
+ catch (_) {
74
+ cgColor = UIColor.blackColor.CGColor;
75
+ }
76
+ const opacity = isNumber(cfg.opacity) ? cfg.opacity : 0.3;
77
+ const radius = isNumber(cfg.radius) ? cfg.radius : 30;
78
+ const offsetX = isNumber(cfg.offset?.x) ? cfg.offset.x : 0;
79
+ const offsetY = isNumber(cfg.offset?.y) ? cfg.offset.y : 8;
80
+ const cornerRadius = layer.cornerRadius || 0;
81
+ const roundedRectPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(CGRectMake(0, 0, bounds.size.width, bounds.size.height), cornerRadius).CGPath;
82
+ const shadowLayer = CALayer.layer();
83
+ // Match the modal's geometry so shadow tracks 1:1.
84
+ shadowLayer.anchorPoint = layer.anchorPoint;
85
+ shadowLayer.bounds = bounds;
86
+ shadowLayer.position = layer.position;
87
+ shadowLayer.transform = layer.transform;
88
+ shadowLayer.shadowColor = cgColor;
89
+ shadowLayer.shadowOpacity = opacity;
90
+ shadowLayer.shadowRadius = radius;
91
+ shadowLayer.shadowOffset = CGSizeMake(offsetX, offsetY);
92
+ // Explicit shadowPath = shadow renders from this shape outward;
93
+ // the layer itself stays fully transparent.
94
+ shadowLayer.shadowPath = roundedRectPath;
95
+ CATransaction.begin();
96
+ CATransaction.setDisableActions(true);
97
+ superlayer.insertSublayerBelow(shadowLayer, layer);
98
+ CATransaction.commit();
99
+ presentedView.__sharedTransitionShadowLayer = shadowLayer;
100
+ }
101
+ /**
102
+ * Mirror the modal layer's geometry onto the sibling shadow layer so the
103
+ * shadow tracks the interactive drag. Called from the gesture handlers
104
+ * after the modal's state has been updated (either via direct transform
105
+ * in morph mode, or via `interactiveController.updateInteractiveTransition`
106
+ * for the non-morph modal/page case driven by UIViewPropertyAnimator).
107
+ *
108
+ * Reads the layer's **presentation** values when an animation is in flight
109
+ * — model values would point at the animation's end state and snap the
110
+ * shadow there. Falls back to model values when no animation is running.
111
+ */
112
+ export function syncInteractiveDismissShadow(presentedView) {
113
+ const shadowLayer = presentedView?.__sharedTransitionShadowLayer;
114
+ if (!shadowLayer || !presentedView?.layer)
115
+ return;
116
+ const layer = presentedView.layer;
117
+ const pres = typeof layer.presentationLayer === 'function' ? layer.presentationLayer() : null;
118
+ const src = pres || layer;
119
+ const b = src.bounds;
120
+ CATransaction.begin();
121
+ CATransaction.setDisableActions(true);
122
+ shadowLayer.bounds = b;
123
+ shadowLayer.position = src.position;
124
+ shadowLayer.anchorPoint = src.anchorPoint;
125
+ shadowLayer.transform = src.transform;
126
+ shadowLayer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(CGRectMake(0, 0, b.size.width, b.size.height), src.cornerRadius || 0).CGPath;
127
+ CATransaction.commit();
128
+ }
129
+ /**
130
+ * Remove the sibling shadow layer. Safe to call repeatedly / when no
131
+ * shadow was applied.
132
+ */
133
+ export function removeInteractiveDismissShadow(presentedView) {
134
+ const shadowLayer = presentedView?.__sharedTransitionShadowLayer;
135
+ if (!shadowLayer)
136
+ return;
137
+ CATransaction.begin();
138
+ CATransaction.setDisableActions(true);
139
+ shadowLayer.removeFromSuperlayer();
140
+ CATransaction.commit();
141
+ presentedView.__sharedTransitionShadowLayer = null;
142
+ }
6
143
  export class SharedTransitionHelper {
7
144
  static animate(state, transitionContext, type) {
8
- const transition = state.instance;
9
145
  setTimeout(async () => {
10
146
  // Run on next tick
11
147
  // ensures that existing UI state finishes before snapshotting
12
148
  // (eg, button touch up state)
149
+ // Any exception thrown before the animation starts would leave `completeTransition` uncalled
150
+ // and UIKit stuck in the middle of the transition (blank page, dead back button, hidden shared views)
151
+ try {
152
+ await SharedTransitionHelper.run(state, transitionContext, type);
153
+ }
154
+ catch (error) {
155
+ SharedTransitionHelper.recover(state, transitionContext, type, error);
156
+ }
157
+ });
158
+ }
159
+ static async run(state, transitionContext, type) {
160
+ const transition = state.instance;
161
+ {
13
162
  switch (state.activeType) {
14
163
  case SharedTransitionAnimationType.present: {
15
164
  // console.log('-- Transition present --');
@@ -25,7 +174,10 @@ export class SharedTransitionHelper {
25
174
  transitionContext.containerView.insertSubviewAboveSubview(transition.presented.view, transition.presenting.view);
26
175
  }
27
176
  transition.presented.view.layoutIfNeeded();
28
- const { sharedElements, presented, presenting } = SharedTransition.getSharedElements(state.page, state.toPage);
177
+ const { sharedElements: allSharedElements, presented, presenting } = SharedTransition.getSharedElements(state.page, state.toPage);
178
+ // like on android, pageStart.sharedTransitionTags restricts the elements which are shared between both pages
179
+ const startTags = state.pageStart?.sharedTransitionTags ? Object.keys(state.pageStart.sharedTransitionTags) : null;
180
+ const sharedElements = startTags?.length ? allSharedElements.filter((v) => startTags.indexOf(v.sharedTransitionTag) !== -1) : allSharedElements;
29
181
  const sharedElementTags = sharedElements.map((v) => v.sharedTransitionTag);
30
182
  if (!transition.sharedElements) {
31
183
  transition.sharedElements = {
@@ -34,6 +186,10 @@ export class SharedTransitionHelper {
34
186
  independent: [],
35
187
  };
36
188
  }
189
+ // Track every matched source view so cleanup can restore alpha,
190
+ // including duplicates (same album surfacing in multiple lists)
191
+ // that we hide but don't create a snapshot for.
192
+ transition.sharedElements._allPresentingViews = sharedElements.slice();
37
193
  if (SharedTransition.DEBUG) {
38
194
  console.log(` ${type}: Present`);
39
195
  console.log(`1. Found sharedTransitionTags to animate:`, sharedElementTags);
@@ -46,12 +202,22 @@ export class SharedTransitionHelper {
46
202
  const pageEndTags = pageEnd?.sharedTransitionTags || {};
47
203
  // console.log('pageEndIndependentTags:', pageEndIndependentTags);
48
204
  const positionSharedTags = async () => {
205
+ const processedTags = new Set();
49
206
  for (const presentingView of sharedElements) {
50
207
  const presentingSharedElement = presentingView.ios;
51
- // console.log('fromTarget instanceof UIImageView:', fromTarget instanceof UIImageView)
52
- // TODO: discuss whether we should check if UIImage/UIImageView type to always snapshot images or if other view types could be duped/added vs. snapshotted
53
- // Note: snapshot may be most efficient/simple
54
- // console.log('---> ', presentingView.sharedTransitionTag, ': ', presentingSharedElement)
208
+ const tag = presentingView.sharedTransitionTag;
209
+ if (processedTags.has(tag)) {
210
+ // The same item can appear in multiple lists on the source page
211
+ // (e.g., a featured album also surfacing in "Recently Played").
212
+ // Each instance has the same sharedTransitionTag. Only the first
213
+ // one becomes the snapshot origin; the rest must still be hidden
214
+ // so they don't show through behind the animating snapshot.
215
+ if (presentingSharedElement) {
216
+ presentingSharedElement.alpha = 0;
217
+ }
218
+ continue;
219
+ }
220
+ processedTags.add(tag);
55
221
  const presentedView = presented.find((v) => v.sharedTransitionTag === presentingView.sharedTransitionTag);
56
222
  const presentedSharedElement = presentedView.ios;
57
223
  const pageEndProps = pageEndTags[presentingView.sharedTransitionTag];
@@ -60,21 +226,31 @@ export class SharedTransitionHelper {
60
226
  await pageEndProps?.callback(presentedView, 'present');
61
227
  }
62
228
  // treat images differently...
229
+ let imageSourceChangeListener;
63
230
  if (presentedSharedElement instanceof UIImageView) {
64
- // in case the image is loaded async, we need to update the snapshot when it changes
65
- // todo: remove listener on transition end
66
- presentedView.on('imageSourceChange', () => {
231
+ // In case the image is loaded async, keep the snapshot's image in sync with
232
+ // the destination view's image. We hold a ref so we can detach the listener
233
+ // on cleanup (the View would otherwise hold a strong ref via the observers
234
+ // map and the snapshot closure would leak).
235
+ imageSourceChangeListener = () => {
67
236
  snapshot.image = iOSUtils.snapshotView(presentedSharedElement, Screen.mainScreen.scale);
68
237
  snapshot.tintColor = presentedSharedElement.tintColor;
69
- });
238
+ };
239
+ presentedView.on('imageSourceChange', imageSourceChangeListener);
70
240
  snapshot.tintColor = presentedSharedElement.tintColor;
71
- snapshot.contentMode = presentedSharedElement.contentMode;
241
+ snapshot.contentMode = getSnapshotContentMode(presentingSharedElement, presentedSharedElement);
242
+ // Seed the snapshot with the source's already-loaded image so the very
243
+ // first frame of the animation isn't blank if the destination image is
244
+ // still loading.
245
+ if (presentingSharedElement instanceof UIImageView) {
246
+ snapshot.image = presentingSharedElement.image;
247
+ }
72
248
  }
73
249
  iOSUtils.copyLayerProperties(snapshot, presentingSharedElement, pageEndProps?.propertiesToMatch);
74
250
  snapshot.clipsToBounds = true;
75
251
  // console.log('---> snapshot: ', snapshot);
76
- const startFrame = presentingSharedElement.convertRectToView(presentingSharedElement.bounds, transitionContext.containerView);
77
- const endFrame = presentedSharedElement.convertRectToView(presentedSharedElement.bounds, transitionContext.containerView);
252
+ const startFrame = getDisplayedFrame(presentingSharedElement, transitionContext.containerView);
253
+ const endFrame = getDisplayedFrame(presentedSharedElement, transitionContext.containerView);
78
254
  snapshot.frame = startFrame;
79
255
  if (SharedTransition.DEBUG) {
80
256
  console.log('---> ', presentingView.sharedTransitionTag, ' frame:', iOSUtils.printCGRect(snapshot.frame));
@@ -96,86 +272,115 @@ export class SharedTransitionHelper {
96
272
  startOpacity: presentedView.opacity,
97
273
  endOpacity: presentingView.opacity,
98
274
  propertiesToMatch: pageEndProps?.propertiesToMatch,
275
+ imageSourceChangeListener,
99
276
  });
100
277
  // set initial opacity to match the source view opacity
101
278
  snapshot.alpha = presentingView.opacity;
102
- // hide both while animating within the transition context
103
- presentingView.opacity = 0;
104
- presentedView.opacity = 0;
279
+ // Hide both while animating in the transition context.
280
+ //
281
+ // We mutate native alpha directly rather than NS `opacity` so the NS-side
282
+ // style remains the user's intended value (typically 1). If we instead set
283
+ // `view.opacity = 0` and then a transition was interrupted before cleanup
284
+ // (or the page was reused), `startOpacity` here could capture 0 from a prior
285
+ // run and the cleanup below would leave the destination invisible.
286
+ presentingSharedElement.alpha = 0;
287
+ presentedSharedElement.alpha = 0;
105
288
  }
106
289
  };
107
290
  const positionIndependentTags = async () => {
108
- // independent tags
109
- for (const tag in pageEndTags) {
110
- // only handle if independent (otherwise it's shared between both pages and handled above)
111
- if (!sharedElementTags.includes(tag)) {
112
- // only consider start when there's a matching end
113
- const pageStartIndependentProps = pageStart?.sharedTransitionTags ? pageStart?.sharedTransitionTags[tag] : null;
114
- // console.log('start:', tag, pageStartIndependentProps);
115
- const pageEndProps = pageEndTags[tag];
116
- let independentView = presenting.find((v) => v.sharedTransitionTag === tag);
117
- let isPresented = false;
291
+ // "Independent" tags appear on only one of the two pages (or were
292
+ // explicitly enumerated in pageEnd.sharedTransitionTags). We auto-discover
293
+ // them so authors don't have to enumerate every tag manually:
294
+ // - source-only (orphan on presenting): fade *out* on present, fade
295
+ // back in on dismiss. e.g., a "FEATURED ALBUM" label on a hero card
296
+ // that has no counterpart on the destination page.
297
+ // - destination-only (orphan on presented): fade *in* on present, fade
298
+ // back out on dismiss. e.g., metadata that only exists on the detail
299
+ // page.
300
+ // Authors can override per-tag via pageStart / pageEnd `sharedTransitionTags`
301
+ // (e.g. add `y: -20` to slide while fading), or opt a view out entirely
302
+ // with `sharedTransitionIgnore`.
303
+ const orphanTags = [];
304
+ const seenOrphan = new Set();
305
+ const addOrphan = (tag) => {
306
+ if (!tag || seenOrphan.has(tag) || sharedElementTags.includes(tag))
307
+ return;
308
+ seenOrphan.add(tag);
309
+ orphanTags.push(tag);
310
+ };
311
+ for (const v of presenting)
312
+ addOrphan(v.sharedTransitionTag);
313
+ for (const v of presented)
314
+ addOrphan(v.sharedTransitionTag);
315
+ // Tags the user listed in pageEnd.sharedTransitionTags but that don't
316
+ // match a real view are silently skipped further down — keep them in
317
+ // the iteration so per-tag config still applies to existing orphans.
318
+ for (const tag in pageEndTags)
319
+ addOrphan(tag);
320
+ for (const tag of orphanTags) {
321
+ const pageStartIndependentProps = pageStart?.sharedTransitionTags ? pageStart?.sharedTransitionTags[tag] : null;
322
+ const pageEndProps = pageEndTags[tag];
323
+ let independentView = presenting.find((v) => v.sharedTransitionTag === tag);
324
+ let isPresented = false;
325
+ if (!independentView) {
326
+ independentView = presented.find((v) => v.sharedTransitionTag === tag);
118
327
  if (!independentView) {
119
- independentView = presented.find((v) => v.sharedTransitionTag === tag);
120
- if (!independentView) {
121
- break;
122
- }
123
- isPresented = true;
124
- }
125
- const independentSharedElement = independentView.ios;
126
- if (pageEndProps?.callback) {
127
- await pageEndProps?.callback(independentView, 'present');
128
- }
129
- // let snapshot: UIImageView;
130
- // if (isPresented) {
131
- // snapshot = UIImageView.alloc().init();
132
- // } else {
133
- const snapshot = UIImageView.alloc().initWithImage(iOSUtils.snapshotView(independentSharedElement, Screen.mainScreen.scale));
134
- // }
135
- if (independentSharedElement instanceof UIImageView) {
136
- // in case the image is loaded async, we need to update the snapshot when it changes
137
- // todo: remove listener on transition end
138
- // if (isPresented) {
139
- // independentView.on('imageSourceChange', () => {
140
- // snapshot.image = iOSNativeHelper.snapshotView(independentSharedElement, Screen.mainScreen.scale);
141
- // snapshot.tintColor = independentSharedElement.tintColor;
142
- // });
143
- // }
144
- snapshot.tintColor = independentSharedElement.tintColor;
145
- snapshot.contentMode = independentSharedElement.contentMode;
328
+ // Tag declared in config but no matching view; skip (don't
329
+ // break — later tags might still resolve).
330
+ continue;
146
331
  }
147
- snapshot.clipsToBounds = true;
148
- const startFrame = independentSharedElement.convertRectToView(independentSharedElement.bounds, transitionContext.containerView);
149
- const startFrameRect = getRectFromProps(pageStartIndependentProps);
150
- // adjust for any specified start positions
151
- const startFrameAdjusted = CGRectMake(startFrame.origin.x + startFrameRect.x, startFrame.origin.y + startFrameRect.y, startFrame.size.width, startFrame.size.height);
152
- // console.log('startFrameAdjusted:', tag, iOSNativeHelper.printCGRect(startFrameAdjusted));
153
- // if (pageStartIndependentProps?.scale) {
154
- // snapshot.transform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(startFrameAdjusted.origin.x, startFrameAdjusted.origin.y), CGAffineTransformMakeScale(pageStartIndependentProps.scale.x, pageStartIndependentProps.scale.y))
155
- // } else {
156
- snapshot.frame = startFrame; //startFrameAdjusted;
157
- // }
158
- if (SharedTransition.DEBUG) {
159
- console.log('---> ', independentView.sharedTransitionTag, ' frame:', iOSUtils.printCGRect(snapshot.frame));
160
- }
161
- const endFrameRect = getRectFromProps(pageEndProps);
162
- const endFrame = CGRectMake(startFrame.origin.x + endFrameRect.x, startFrame.origin.y + endFrameRect.y, startFrame.size.width, startFrame.size.height);
163
- // console.log('endFrame:', tag, iOSNativeHelper.printCGRect(endFrame));
164
- transition.sharedElements.independent.push({
165
- view: independentView,
166
- isPresented,
167
- startFrame,
168
- snapshot,
169
- endFrame,
170
- startTransform: independentSharedElement.transform,
171
- scale: pageEndProps.scale,
172
- startOpacity: independentView.opacity,
173
- endOpacity: isNumber(pageEndProps.opacity) ? pageEndProps.opacity : 0,
174
- propertiesToMatch: pageEndProps?.propertiesToMatch,
175
- zIndex: isNumber(pageEndProps?.zIndex) ? pageEndProps.zIndex : 0,
176
- });
177
- independentView.opacity = 0;
332
+ isPresented = true;
333
+ }
334
+ const independentSharedElement = independentView.ios;
335
+ if (pageEndProps?.callback) {
336
+ await pageEndProps?.callback(independentView, 'present');
178
337
  }
338
+ const snapshot = UIImageView.alloc().initWithImage(iOSUtils.snapshotView(independentSharedElement, Screen.mainScreen.scale));
339
+ if (independentSharedElement instanceof UIImageView) {
340
+ snapshot.tintColor = independentSharedElement.tintColor;
341
+ snapshot.contentMode = independentSharedElement.contentMode;
342
+ }
343
+ snapshot.clipsToBounds = true;
344
+ // Copy layer properties (cornerRadius, borderWidth/Color)
345
+ // from the source view so the snapshot renders with the
346
+ // same rounded corners. Without this, source-side
347
+ // thumbnails/buttons appear with sharp square corners
348
+ // during a non-morph interactive dismiss — the snapshot
349
+ // is what the user sees through the dismissing modal,
350
+ // and its layer is freshly created with cornerRadius 0.
351
+ iOSUtils.copyLayerProperties(snapshot, independentSharedElement, pageEndProps?.propertiesToMatch);
352
+ const startFrame = independentSharedElement.convertRectToView(independentSharedElement.bounds, transitionContext.containerView);
353
+ snapshot.frame = startFrame;
354
+ if (SharedTransition.DEBUG) {
355
+ console.log('---> ', independentView.sharedTransitionTag, ' frame:', iOSUtils.printCGRect(snapshot.frame));
356
+ }
357
+ const endFrameRect = getRectFromProps(pageEndProps);
358
+ const endFrame = CGRectMake(startFrame.origin.x + (endFrameRect.x || 0), startFrame.origin.y + (endFrameRect.y || 0), startFrame.size.width, startFrame.size.height);
359
+ // Opacity defaults are side-aware: source-only orphans fade out (1 → 0),
360
+ // destination-only orphans fade in (0 → 1). The values are read back
361
+ // during dismiss as `endOpacity → startOpacity` so the return phase is
362
+ // automatically symmetric. Author-supplied opacity always wins.
363
+ const startOpacity = isNumber(pageStartIndependentProps?.opacity) ? pageStartIndependentProps.opacity : isPresented ? 0 : independentView.opacity;
364
+ const endOpacity = isNumber(pageEndProps?.opacity) ? pageEndProps.opacity : isPresented ? independentView.opacity : 0;
365
+ // Snapshot's initial visible alpha. Default UIImageView alpha is 1;
366
+ // destination-only orphans need to start at 0 so the fade-in is
367
+ // visible, hence we always set it explicitly.
368
+ snapshot.alpha = startOpacity;
369
+ transition.sharedElements.independent.push({
370
+ view: independentView,
371
+ isPresented,
372
+ startFrame,
373
+ snapshot,
374
+ endFrame,
375
+ startTransform: independentSharedElement.transform,
376
+ scale: pageEndProps?.scale,
377
+ startOpacity,
378
+ endOpacity,
379
+ propertiesToMatch: pageEndProps?.propertiesToMatch,
380
+ zIndex: isNumber(pageEndProps?.zIndex) ? pageEndProps.zIndex : 0,
381
+ });
382
+ // Native alpha; see comment in positionSharedTags.
383
+ independentSharedElement.alpha = 0;
179
384
  }
180
385
  };
181
386
  // position all sharedTransitionTag elements
@@ -183,7 +388,7 @@ export class SharedTransitionHelper {
183
388
  await positionIndependentTags();
184
389
  // combine to order by zIndex and add to transition context
185
390
  const snapshotData = transition.sharedElements.presenting.concat(transition.sharedElements.independent);
186
- snapshotData.sort((a, b) => (a.zIndex > b.zIndex ? 1 : -1));
391
+ snapshotData.sort((a, b) => (a.zIndex || 0) - (b.zIndex || 0));
187
392
  if (SharedTransition.DEBUG) {
188
393
  console.log(`zIndex settings:`, snapshotData.map((s) => {
189
394
  return {
@@ -199,16 +404,56 @@ export class SharedTransitionHelper {
199
404
  // Important: always set after above shared element positions have had their start positions set
200
405
  transition.presented.view.alpha = isNumber(pageStart?.opacity) ? pageStart?.opacity : 0;
201
406
  transition.presented.view.frame = CGRectMake(startFrame.x, startFrame.y, startFrame.width, startFrame.height);
407
+ // Optional top-corner rounding for sheet-style transitions (e.g.
408
+ // a modal that's rounded at the bottom of the screen and flattens
409
+ // as it slides up). Setting maskedCorners and masksToBounds here
410
+ // (before the animation) so they're stable during the animated
411
+ // cornerRadius change.
412
+ if (isNumber(pageStart?.cornerRadius) || isNumber(pageEnd?.cornerRadius)) {
413
+ const layer = transition.presented.view.layer;
414
+ // top-left | top-right | bottom-left | bottom-right (CACornerMask bits)
415
+ layer.maskedCorners = 15;
416
+ layer.masksToBounds = true;
417
+ if (isNumber(pageStart?.cornerRadius)) {
418
+ layer.cornerRadius = pageStart.cornerRadius;
419
+ }
420
+ }
202
421
  const cleanupPresent = () => {
203
422
  for (const presented of transition.sharedElements.presented) {
204
- presented.view.opacity = presented.startOpacity;
423
+ // Detach the per-transition imageSourceChange listener registered
424
+ // during positionSharedTags so it doesn't leak (the snapshot is gone).
425
+ if (presented.imageSourceChangeListener) {
426
+ presented.view.off('imageSourceChange', presented.imageSourceChangeListener);
427
+ presented.imageSourceChangeListener = null;
428
+ }
429
+ // Restore the destination native alpha from the NS opacity (the source
430
+ // of truth). NS opacity wasn't modified during the transition, so this
431
+ // reflects the user's intended visibility (typically 1).
432
+ presented.view.ios.alpha = presented.view.opacity;
433
+ }
434
+ // Restore native alpha on every source view we touched — including
435
+ // duplicates that share a sharedTransitionTag and were hidden without
436
+ // a snapshot. Even though the source page is being removed, the View
437
+ // instances may be reused on subsequent navigations.
438
+ for (const sourceView of transition.sharedElements._allPresentingViews || []) {
439
+ if (sourceView?.ios) {
440
+ sourceView.ios.alpha = sourceView.opacity;
441
+ }
205
442
  }
206
443
  for (const presenting of transition.sharedElements.presenting) {
207
444
  presenting.snapshot.removeFromSuperview();
445
+ if (type === 'page') {
446
+ // the page we left is detached: give its views back so none stays hidden when it is shown again
447
+ // (the way back is not necessarily done with this transition instance nor with the same shared elements)
448
+ presenting.view.opacity = presenting.startOpacity;
449
+ }
208
450
  }
209
451
  for (const independent of transition.sharedElements.independent) {
210
452
  independent.snapshot.removeFromSuperview();
211
453
  if (independent.isPresented) {
454
+ independent.view.ios.alpha = independent.view.opacity;
455
+ }
456
+ else if (type === 'page') {
212
457
  independent.view.opacity = independent.startOpacity;
213
458
  }
214
459
  }
@@ -232,6 +477,12 @@ export class SharedTransitionHelper {
232
477
  transition.presented.view.alpha = isNumber(pageEnd?.opacity) ? pageEnd?.opacity : 1;
233
478
  const endFrame = getRectFromProps(pageEnd);
234
479
  transition.presented.view.frame = CGRectMake(endFrame.x, endFrame.y, endFrame.width, endFrame.height);
480
+ // Animate cornerRadius alongside the page frame. Implicit animation
481
+ // of cornerRadius is supported on iOS 11+, both inside
482
+ // UIView.animateWith… and UIViewPropertyAnimator's animations block.
483
+ if (isNumber(pageEnd?.cornerRadius)) {
484
+ transition.presented.view.layer.cornerRadius = pageEnd.cornerRadius;
485
+ }
235
486
  if (pageOut) {
236
487
  if (isNumber(pageOut.opacity)) {
237
488
  transition.presenting.view.alpha = pageOut?.opacity;
@@ -248,8 +499,11 @@ export class SharedTransitionHelper {
248
499
  // owner.presented.view.layoutIfNeeded();
249
500
  for (const presented of transition.sharedElements.presented) {
250
501
  const presentingMatch = transition.sharedElements.presenting.find((v) => v.view.sharedTransitionTag === presented.view.sharedTransitionTag);
502
+ if (!presentingMatch) {
503
+ continue;
504
+ }
251
505
  // Workaround wrong origin due ongoing layout process.
252
- const updatedEndFrame = presented.view.ios.convertRectToView(presented.view.ios.bounds, transitionContext.containerView);
506
+ const updatedEndFrame = getDisplayedFrame(presented.view.ios, transitionContext.containerView);
253
507
  const correctedEndFrame = CGRectMake(updatedEndFrame.origin.x, updatedEndFrame.origin.y, presentingMatch.endFrame.size.width, presentingMatch.endFrame.size.height);
254
508
  presentingMatch.snapshot.frame = correctedEndFrame;
255
509
  // apply view and layer properties to the snapshot view to match the source/presented view
@@ -310,23 +564,57 @@ export class SharedTransitionHelper {
310
564
  });
311
565
  if (type === 'page') {
312
566
  transitionContext.containerView.insertSubviewBelowSubview(transition.presenting.view, transition.presented.view);
567
+ // UIKit's standard pop places the incoming source view off to the
568
+ // left so it can slide into position; for custom shared transitions
569
+ // (where the destination either slides down or morphs to source) we
570
+ // don't want that lateral slide. Pin the source to its fullscreen
571
+ // frame so it stays put underneath the animating destination.
572
+ // Users can still opt into a custom source animation via `pageOut`.
573
+ const sourceDefaults = getRectFromProps(null);
574
+ transition.presenting.view.frame = CGRectMake(0, 0, sourceDefaults.width, sourceDefaults.height);
575
+ }
576
+ // Morph + interactive dismiss: the gesture handler drives the
577
+ // animation via transforms and finalizes by calling cancel/finish
578
+ // on the transitionContext. Running the standard snapshot + spring
579
+ // rig here would race that and frequently call completeTransition(true)
580
+ // *before* the user's gesture ended — causing the dismiss to commit
581
+ // even on a cancel. Skip the rest of the dismiss setup entirely.
582
+ if (state.interactive?.dismiss?.morph && state.interactiveBegan) {
583
+ return;
313
584
  }
314
585
  // console.log('transitionContext.containerView.subviews.count:', transitionContext.containerView.subviews.count);
315
586
  if (SharedTransition.DEBUG) {
316
587
  console.log(` ${type}: Dismiss`);
317
- console.log(`1. Dismiss sharedTransitionTags to animate:`, transition.sharedElements.presented.map((p) => p.view.sharedTransitionTag));
588
+ console.log(`1. Dismiss sharedTransitionTags to animate:`, transition.sharedElements?.presented?.map((p) => p.view.sharedTransitionTag));
318
589
  console.log(`2. Add back previously stored sharedElements to dismiss:`);
319
590
  }
320
591
  const pageOut = state.pageOut;
321
592
  const pageEnd = state.pageEnd;
322
593
  const pageEndTags = pageEnd?.sharedTransitionTags || {};
323
594
  const pageReturn = state.pageReturn;
595
+ if (type === 'page') {
596
+ // rebuild from what is currently shown instead of replaying what was recorded on the way in
597
+ SharedTransitionHelper.rebuildDismissElements(state, transitionContext);
598
+ }
599
+ else if (!transition.sharedElements) {
600
+ transition.sharedElements = { presented: [], presenting: [], independent: [] };
601
+ }
324
602
  for (const p of transition.sharedElements.presented) {
325
- p.view.opacity = 0;
603
+ // Use native alpha (not NS opacity) so we don't pollute the NS-side
604
+ // value if the dismiss is interrupted; cleanup restores from NS opacity.
605
+ p.view.ios.alpha = 0;
606
+ }
607
+ // Ensure top-corner masking + clipping is in place before we animate
608
+ // cornerRadius back toward the start value. If the present pass already
609
+ // set these, this is a harmless no-op.
610
+ if (isNumber(pageReturn?.cornerRadius)) {
611
+ const layer = transition.presented.view.layer;
612
+ layer.maskedCorners = 15; // top-left | top-right | bottom-left | bottom-right
613
+ layer.masksToBounds = true;
326
614
  }
327
615
  // combine to order by zIndex and add to transition context
328
616
  const snapshotData = transition.sharedElements.presenting.concat(transition.sharedElements.independent);
329
- snapshotData.sort((a, b) => (a.zIndex > b.zIndex ? 1 : -1));
617
+ snapshotData.sort((a, b) => (a.zIndex || 0) - (b.zIndex || 0));
330
618
  if (SharedTransition.DEBUG) {
331
619
  console.log(`zIndex settings:`, snapshotData.map((s) => {
332
620
  return {
@@ -344,6 +632,11 @@ export class SharedTransitionHelper {
344
632
  }
345
633
  // now that all the callbacks had their chance to run, we can take the snapshots
346
634
  for (const data of snapshotData) {
635
+ if (data.rebuilt) {
636
+ // snapshot of the popped view already taken and positioned
637
+ transitionContext.containerView.addSubview(data.snapshot);
638
+ continue;
639
+ }
347
640
  const view = data.view.ios;
348
641
  const currentAlpha = view.alpha;
349
642
  if (pageReturn?.useStartOpacity) {
@@ -365,13 +658,43 @@ export class SharedTransitionHelper {
365
658
  // add snapshot to animate
366
659
  transitionContext.containerView.addSubview(data.snapshot);
367
660
  }
661
+ // Hide every source-side shared element now that snapshots have been
662
+ // captured. The animating snapshot covers them; without this, the user
663
+ // sees a "double image" — the real source element AND the snapshot
664
+ // animating over it back to its position. Use the full list (not just
665
+ // the deduped `presenting`) so duplicates from sister lists are hidden
666
+ // too. Restored in cleanupDismiss below.
667
+ for (const sourceView of transition.sharedElements._allPresentingViews || []) {
668
+ if (sourceView?.ios) {
669
+ sourceView.ios.alpha = 0;
670
+ }
671
+ }
368
672
  const cleanupDismiss = () => {
673
+ // Restore alpha on every source view we hid — including duplicate
674
+ // sources with the same sharedTransitionTag — using NS opacity as
675
+ // the source of truth.
676
+ for (const sourceView of transition.sharedElements._allPresentingViews || []) {
677
+ if (sourceView?.ios) {
678
+ sourceView.ios.alpha = sourceView.opacity;
679
+ }
680
+ }
369
681
  for (const presenting of transition.sharedElements.presenting) {
370
- presenting.view.opacity = presenting.startOpacity;
371
682
  presenting.snapshot.removeFromSuperview();
372
683
  }
684
+ for (const presented of transition.sharedElements.presented) {
685
+ // Detach the imageSourceChange listener and restore alpha. Even though
686
+ // the destination page is being torn down, NS Views can outlive their
687
+ // nativeView and we shouldn't leak observers.
688
+ if (presented.imageSourceChangeListener) {
689
+ presented.view.off('imageSourceChange', presented.imageSourceChangeListener);
690
+ presented.imageSourceChangeListener = null;
691
+ }
692
+ if (presented.view.ios) {
693
+ presented.view.ios.alpha = presented.view.opacity;
694
+ }
695
+ }
373
696
  for (const independent of transition.sharedElements.independent) {
374
- independent.view.opacity = independent.startOpacity;
697
+ independent.view.ios.alpha = independent.view.opacity;
375
698
  independent.snapshot.removeFromSuperview();
376
699
  }
377
700
  SharedTransition.finishState(transition.id);
@@ -390,6 +713,11 @@ export class SharedTransitionHelper {
390
713
  transition.presented.view.alpha = isNumber(pageReturn?.opacity) ? pageReturn?.opacity : 0;
391
714
  const endFrame = getRectFromProps(pageReturn, getPageStartDefaultsForType(type));
392
715
  transition.presented.view.frame = CGRectMake(endFrame.x, endFrame.y, endFrame.width, endFrame.height);
716
+ // Animate cornerRadius back toward the start value (e.g. a sheet
717
+ // re-rounds as it slides offscreen).
718
+ if (isNumber(pageReturn?.cornerRadius)) {
719
+ transition.presented.view.layer.cornerRadius = pageReturn.cornerRadius;
720
+ }
393
721
  if (pageOut) {
394
722
  // always return to defaults if pageOut had been used
395
723
  transition.presenting.view.alpha = 1;
@@ -439,8 +767,147 @@ export class SharedTransitionHelper {
439
767
  break;
440
768
  }
441
769
  }
770
+ }
771
+ }
772
+ /**
773
+ * Called when the animation setup threw: put everything back in a sane state and always complete the transition,
774
+ * otherwise UIKit stays in the middle of the navigation transition.
775
+ */
776
+ static recover(state, transitionContext, type, error) {
777
+ const transition = state.instance;
778
+ console.error(`SharedTransition (${state.activeType === SharedTransitionAnimationType.present ? 'present' : 'dismiss'}) failed, completing the transition without animation:`, error);
779
+ const isPresent = state.activeType === SharedTransitionAnimationType.present;
780
+ try {
781
+ const elements = transition?.sharedElements;
782
+ if (elements) {
783
+ for (const p of elements.presented || []) {
784
+ p.view.opacity = isNumber(p.startOpacity) ? p.startOpacity : 1;
785
+ }
786
+ for (const p of elements.presenting || []) {
787
+ p.view.opacity = isNumber(p.startOpacity) ? p.startOpacity : 1;
788
+ p.snapshot?.removeFromSuperview();
789
+ }
790
+ for (const p of elements.independent || []) {
791
+ p.view.opacity = isNumber(p.startOpacity) ? p.startOpacity : 1;
792
+ p.snapshot?.removeFromSuperview();
793
+ }
794
+ }
795
+ if (type === 'page') {
796
+ const shown = isPresent ? transition.presented : transition.presenting;
797
+ if (shown?.view) {
798
+ shown.view.alpha = 1;
799
+ const frame = getRectFromProps(isPresent ? state.pageEnd : null);
800
+ shown.view.frame = CGRectMake(frame.x, frame.y, frame.width, frame.height);
801
+ }
802
+ }
803
+ }
804
+ catch (err) {
805
+ if (Trace.isEnabled()) {
806
+ Trace.write(`SharedTransition recover failed: ${err}`, Trace.categories.Transition, Trace.messageType.error);
807
+ }
808
+ }
809
+ if (isPresent) {
810
+ SharedTransition.updateState(transition.id, { activeType: SharedTransitionAnimationType.dismiss });
811
+ }
812
+ else {
813
+ SharedTransition.finishState(transition.id);
814
+ transition.sharedElements = null;
815
+ }
816
+ // when the user cancelled (interactive pop) we must report it, otherwise the navigation controller is left inconsistent
817
+ transitionContext.completeTransition(!transitionContext.transitionWasCancelled);
818
+ SharedTransition.notifyEvent(SharedTransition.finishedEvent, {
819
+ id: transition.id,
820
+ type,
821
+ action: isPresent ? 'present' : 'dismiss',
442
822
  });
443
823
  }
824
+ /**
825
+ * Rebuilds the shared elements to animate on the way back from the pages that are currently shown.
826
+ * The elements recorded on the way in can not be reused: the popped page might now show another photo (same tag
827
+ * pattern, other value) or its views might have been recycled, and the transition passed to goBack can be a new instance.
828
+ */
829
+ static rebuildDismissElements(state, transitionContext) {
830
+ const transition = state.instance;
831
+ // roles are set from the navigation operation (see PageTransition.iosNavigatedController)
832
+ const poppedPage = getControllerPage(transition.presented);
833
+ const returnPage = state.page ?? getControllerPage(transition.presenting);
834
+ const previous = transition.sharedElements;
835
+ const presenting = [];
836
+ const presented = [];
837
+ const pageEndTags = state.pageEnd?.sharedTransitionTags || {};
838
+ const containerView = transitionContext.containerView;
839
+ // the page we go back to was removed from the container during the present
840
+ transition.presenting?.view?.layoutIfNeeded();
841
+ if (SharedTransition.DEBUG) {
842
+ console.log(`Dismiss: popped page ${poppedPage}, return page ${returnPage}`);
843
+ }
844
+ if (poppedPage && returnPage) {
845
+ const { sharedElements, presented: poppedViews } = SharedTransition.getSharedElements(returnPage, poppedPage);
846
+ if (SharedTransition.DEBUG) {
847
+ console.log(`Dismiss: tags on return page ${sharedElements.map((v) => v.sharedTransitionTag)}, on popped page ${poppedViews.map((v) => v.sharedTransitionTag)}`);
848
+ }
849
+ const tagFilter = state.pageStart?.sharedTransitionTags ? Object.keys(state.pageStart.sharedTransitionTags) : null;
850
+ for (const returnView of sharedElements) {
851
+ const tag = returnView.sharedTransitionTag;
852
+ if (tagFilter?.length && tagFilter.indexOf(tag) === -1) {
853
+ continue;
854
+ }
855
+ const poppedView = poppedViews.find((v) => v.sharedTransitionTag === tag);
856
+ const returnNative = returnView.ios;
857
+ const poppedNative = poppedView?.ios;
858
+ if (!returnNative || !poppedNative || !poppedNative.window) {
859
+ continue;
860
+ }
861
+ const pageEndProps = pageEndTags[tag];
862
+ const recorded = previous?.presenting?.find((p) => p.view === returnView);
863
+ // the view was hidden on the way in
864
+ const startOpacity = recorded ? recorded.startOpacity : returnView.opacity > 0 ? returnView.opacity : 1;
865
+ const poppedFrame = getDisplayedFrame(poppedNative, containerView);
866
+ const returnFrame = getDisplayedFrame(returnNative, containerView);
867
+ const snapshot = UIImageView.alloc().init();
868
+ if (poppedNative instanceof UIImageView) {
869
+ snapshot.tintColor = poppedNative.tintColor;
870
+ snapshot.contentMode = getSnapshotContentMode(returnNative, poppedNative);
871
+ }
872
+ snapshot.image = iOSUtils.snapshotView(poppedNative, Screen.mainScreen.scale);
873
+ iOSUtils.copyLayerProperties(snapshot, poppedNative, pageEndProps?.propertiesToMatch);
874
+ snapshot.clipsToBounds = true;
875
+ snapshot.frame = poppedFrame;
876
+ snapshot.alpha = poppedView.opacity;
877
+ presenting.push({
878
+ view: returnView,
879
+ startFrame: returnFrame,
880
+ endFrame: poppedFrame,
881
+ snapshot,
882
+ startOpacity,
883
+ endOpacity: poppedView.opacity,
884
+ propertiesToMatch: pageEndProps?.propertiesToMatch,
885
+ zIndex: isNumber(pageEndProps?.zIndex) ? pageEndProps.zIndex : 0,
886
+ rebuilt: true,
887
+ });
888
+ presented.push({
889
+ view: poppedView,
890
+ startFrame: poppedFrame,
891
+ endFrame: returnFrame,
892
+ startOpacity: poppedView.opacity,
893
+ endOpacity: startOpacity,
894
+ propertiesToMatch: pageEndProps?.propertiesToMatch,
895
+ });
896
+ // hide both while animating within the transition context
897
+ returnView.opacity = 0;
898
+ poppedView.opacity = 0;
899
+ }
900
+ }
901
+ // independent elements are only recorded on the way in
902
+ transition.sharedElements = {
903
+ presented,
904
+ presenting,
905
+ independent: previous?.independent || [],
906
+ };
907
+ for (const independent of transition.sharedElements.independent) {
908
+ independent.view.opacity = 0;
909
+ }
910
+ }
444
911
  static interactiveStart(state, interactiveState, type) {
445
912
  SharedTransition.notifyEvent(SharedTransition.startedEvent, {
446
913
  id: state.instance.id,
@@ -450,20 +917,79 @@ export class SharedTransitionHelper {
450
917
  switch (type) {
451
918
  case 'page':
452
919
  interactiveState.transitionContext.containerView.insertSubviewBelowSubview(state.instance.presenting.view, state.instance.presented.view);
920
+ // Pin the source view to its fullscreen frame so it doesn't slide
921
+ // in from off-left as the user drags. The default UIKit pop expects
922
+ // to animate the source from off-left; for shared-element / morph
923
+ // transitions we want the source to stay put underneath the
924
+ // animating destination so the visuals feel connected.
925
+ {
926
+ const sourceDefaults = getRectFromProps(null);
927
+ state.instance.presenting.view.frame = CGRectMake(0, 0, sourceDefaults.width, sourceDefaults.height);
928
+ }
929
+ SharedTransitionHelper.rebuildDismissElements(state, interactiveState.transitionContext);
453
930
  break;
454
931
  }
932
+ // Apply the dismiss shadow here, not from the gesture handler. UIKit
933
+ // reparents the presented view into the transition containerView as
934
+ // part of starting the interactive transition; applying earlier would
935
+ // attach the shadow to the now-orphaned old superlayer.
936
+ if (state.interactive?.dismiss?.shadow && state.instance?.presented?.view) {
937
+ applyInteractiveDismissShadow(state.instance.presented.view, state.interactive.dismiss.shadow);
938
+ }
455
939
  }
456
940
  static interactiveUpdate(state, interactiveState, type, percent) {
457
941
  if (interactiveState) {
942
+ if (state.interactive?.dismiss?.morph) {
943
+ // Morph mode: the gesture handler drives the destination view's
944
+ // transform directly. We only forward the event so observers can
945
+ // react to the gesture's percentage.
946
+ SharedTransition.notifyEvent(SharedTransition.interactiveUpdateEvent, {
947
+ id: state?.instance?.id,
948
+ type,
949
+ percent,
950
+ });
951
+ return;
952
+ }
458
953
  if (!interactiveState.added) {
954
+ // Defer setup until the gesture has clearly committed to a horizontal
955
+ // dismiss motion. A vertical scroll on a descendant scroll view also
956
+ // triggers the page-level pan gesture (NS pan recognizers don't yield
957
+ // to scroll-view pans by default), producing near-zero percent values.
958
+ // Without this guard we'd mount the dismiss snapshots and hide the
959
+ // destination during a scroll, making the image look "stuck" until the
960
+ // cancel animation runs.
961
+ if (Math.abs(percent) < 0.05) {
962
+ return;
963
+ }
459
964
  interactiveState.added = true;
460
965
  for (const p of state.instance.sharedElements.presented) {
461
- p.view.opacity = 0;
966
+ // Native alpha (not NS opacity) for the same reason as the dismiss path:
967
+ // if the user lets go without crossing the threshold, cancel uses NS
968
+ // opacity as source of truth to restore.
969
+ p.view.ios.alpha = 0;
462
970
  }
463
971
  for (const p of state.instance.sharedElements.presenting) {
464
972
  p.snapshot.alpha = p.endOpacity;
465
973
  interactiveState.transitionContext.containerView.addSubview(p.snapshot);
466
974
  }
975
+ // Re-mount independent (orphan) snapshots so they're available to
976
+ // animate alongside the gesture. They were removed in present cleanup
977
+ // but the records (including their snapshots) live on transition.sharedElements.
978
+ // Source-only orphans were left at alpha 0 since present; their snapshots
979
+ // pick up where the present animation left off (endOpacity).
980
+ for (const ind of state.instance.sharedElements.independent) {
981
+ ind.snapshot.alpha = ind.endOpacity;
982
+ interactiveState.transitionContext.containerView.addSubview(ind.snapshot);
983
+ }
984
+ // Hide every source-side shared element (including duplicates that share
985
+ // a sharedTransitionTag in sister lists) so the user only sees the
986
+ // animating snapshot — not the snapshot AND the real source element
987
+ // simultaneously ("double image" during interactive dismissal).
988
+ for (const sourceView of state.instance.sharedElements._allPresentingViews || []) {
989
+ if (sourceView?.ios) {
990
+ sourceView.ios.alpha = 0;
991
+ }
992
+ }
467
993
  const pageStart = state.pageStart;
468
994
  const startFrame = getRectFromProps(pageStart, getPageStartDefaultsForType(type));
469
995
  interactiveState.propertyAnimator = UIViewPropertyAnimator.alloc().initWithDurationDampingRatioAnimations(1, 1, () => {
@@ -472,8 +998,25 @@ export class SharedTransitionHelper {
472
998
  iOSUtils.copyLayerProperties(p.snapshot, p.view.ios, p.propertiesToMatch);
473
999
  p.snapshot.alpha = 1;
474
1000
  }
1001
+ // Animate orphan snapshots back toward their start state alongside
1002
+ // the rest of the dismiss. For source-only orphans this is the
1003
+ // fade-back-in that mirrors the fade-out of present.
1004
+ for (const ind of state.instance.sharedElements.independent) {
1005
+ ind.snapshot.alpha = ind.startOpacity;
1006
+ if (ind.scale) {
1007
+ ind.snapshot.transform = ind.startTransform;
1008
+ }
1009
+ else {
1010
+ ind.snapshot.frame = ind.startFrame;
1011
+ }
1012
+ }
475
1013
  state.instance.presented.view.alpha = isNumber(state.pageReturn?.opacity) ? state.pageReturn?.opacity : 0;
476
1014
  state.instance.presented.view.frame = CGRectMake(startFrame.x, startFrame.y, state.instance.presented.view.bounds.size.width, state.instance.presented.view.bounds.size.height);
1015
+ // Drive cornerRadius via the same percent the user controls — round
1016
+ // the page back up as they pan it offscreen.
1017
+ if (isNumber(state.pageReturn?.cornerRadius)) {
1018
+ state.instance.presented.view.layer.cornerRadius = state.pageReturn.cornerRadius;
1019
+ }
477
1020
  });
478
1021
  }
479
1022
  interactiveState.propertyAnimator.fractionComplete = percent;
@@ -485,17 +1028,108 @@ export class SharedTransitionHelper {
485
1028
  }
486
1029
  }
487
1030
  static interactiveCancel(state, interactiveState, type) {
1031
+ if (state?.instance && interactiveState && state.interactive?.dismiss?.morph) {
1032
+ // Morph mode cancel — spring the destination view back to identity.
1033
+ const view = state.instance.presented?.view;
1034
+ let didFinalize = false;
1035
+ const finalize = () => {
1036
+ if (didFinalize)
1037
+ return;
1038
+ didFinalize = true;
1039
+ if (view)
1040
+ view.transform = CGAffineTransformIdentity;
1041
+ // Restore the source-side element alphas that the gesture hid on
1042
+ // engagement so the source page is correct when shown again.
1043
+ for (const v of state.instance.sharedElements?._allPresentingViews || []) {
1044
+ if (v?.ios)
1045
+ v.ios.alpha = v.opacity;
1046
+ }
1047
+ if (interactiveState.transitionContext) {
1048
+ interactiveState.transitionContext.cancelInteractiveTransition();
1049
+ interactiveState.transitionContext.completeTransition(false);
1050
+ }
1051
+ SharedTransition.updateState(state?.instance?.id, {
1052
+ interactiveBegan: false,
1053
+ interactiveCancelled: true,
1054
+ });
1055
+ SharedTransition.notifyEvent(SharedTransition.interactiveCancelledEvent, {
1056
+ id: state?.instance?.id,
1057
+ type,
1058
+ });
1059
+ };
1060
+ if (view) {
1061
+ iOSUtils.animateWithSpring({
1062
+ animations: () => {
1063
+ view.transform = CGAffineTransformIdentity;
1064
+ // Cross-fade sources back IN PARALLEL with the spring so
1065
+ // they're visible from frame one of the snap-back. This
1066
+ // also makes the source restoration robust to a new
1067
+ // gesture interrupting our completion callback.
1068
+ for (const v of state.instance.sharedElements?._allPresentingViews || []) {
1069
+ if (v?.ios)
1070
+ v.ios.alpha = v.opacity;
1071
+ }
1072
+ },
1073
+ completion: () => finalize(),
1074
+ });
1075
+ // Safety: ensure finalize runs even if the animation completion
1076
+ // is dropped (e.g. interrupted by another gesture).
1077
+ setTimeout(finalize, 800);
1078
+ }
1079
+ else {
1080
+ finalize();
1081
+ }
1082
+ return;
1083
+ }
1084
+ if (state?.instance && interactiveState && !interactiveState.added) {
1085
+ // The gesture engaged the interactive transition but never crossed the
1086
+ // motion threshold in interactiveUpdate (e.g., the user was scrolling
1087
+ // vertically). Nothing was visually set up — just tell UIKit we're
1088
+ // cancelling and clear the flags.
1089
+ if (interactiveState.transitionContext) {
1090
+ interactiveState.transitionContext.cancelInteractiveTransition();
1091
+ interactiveState.transitionContext.completeTransition(false);
1092
+ }
1093
+ SharedTransition.updateState(state?.instance?.id, {
1094
+ interactiveBegan: false,
1095
+ interactiveCancelled: true,
1096
+ });
1097
+ SharedTransition.notifyEvent(SharedTransition.interactiveCancelledEvent, {
1098
+ id: state?.instance?.id,
1099
+ type,
1100
+ });
1101
+ return;
1102
+ }
488
1103
  if (state?.instance && interactiveState?.added && interactiveState?.propertyAnimator) {
489
1104
  interactiveState.propertyAnimator.reversed = true;
490
1105
  const duration = isNumber(state.pageEnd?.duration) ? state.pageEnd?.duration / 1000 : CORE_ANIMATION_DEFAULTS.duration;
491
1106
  interactiveState.propertyAnimator.continueAnimationWithTimingParametersDurationFactor(null, duration);
492
1107
  setTimeout(() => {
493
1108
  for (const p of state.instance.sharedElements.presented) {
494
- p.view.opacity = 1;
1109
+ // Restore native alpha from NS opacity (the user-intended value).
1110
+ p.view.ios.alpha = p.view.opacity;
1111
+ }
1112
+ // Restore alpha on every source view we hid during interactiveUpdate
1113
+ // (including duplicates from sister lists).
1114
+ for (const sourceView of state.instance.sharedElements._allPresentingViews || []) {
1115
+ if (sourceView?.ios) {
1116
+ sourceView.ios.alpha = sourceView.opacity;
1117
+ }
495
1118
  }
496
1119
  for (const p of state.instance.sharedElements.presenting) {
497
1120
  p.snapshot.removeFromSuperview();
498
1121
  }
1122
+ // Tear down orphan snapshots that interactiveUpdate re-mounted. The
1123
+ // source-only orphans' view.alpha stays at 0 — we're returning to the
1124
+ // presented (modal-on-top) state, so they should remain hidden until
1125
+ // a real dismiss completes. Cancel/finish for the next dismiss owns
1126
+ // the eventual restore.
1127
+ for (const ind of state.instance.sharedElements.independent) {
1128
+ ind.snapshot.removeFromSuperview();
1129
+ // Reset snapshot alpha to its post-present end state so a subsequent
1130
+ // interactiveUpdate picks up from the right place.
1131
+ ind.snapshot.alpha = ind.endOpacity;
1132
+ }
499
1133
  state.instance.presented.view.alpha = 1;
500
1134
  interactiveState.propertyAnimator = null;
501
1135
  interactiveState.added = false;
@@ -513,15 +1147,263 @@ export class SharedTransitionHelper {
513
1147
  }
514
1148
  }
515
1149
  static interactiveFinish(state, interactiveState, type) {
1150
+ if (state?.instance && interactiveState && state.interactive?.dismiss?.morph) {
1151
+ // Morph mode finish — animate the destination view to the matching
1152
+ // source element's frame and fade it out, then complete.
1153
+ const view = state.instance.presented?.view;
1154
+ const destPresented = state.instance.sharedElements?.presented?.[0];
1155
+ const destTag = destPresented?.view?.sharedTransitionTag;
1156
+ const matchingSource = state.instance.sharedElements?.presenting?.find?.((p) => p.view.sharedTransitionTag === destTag);
1157
+ const srcIos = matchingSource?.view?.ios;
1158
+ const destSharedIos = destPresented?.view?.ios;
1159
+ const containerView = interactiveState.transitionContext?.containerView;
1160
+ let targetTransform = null;
1161
+ if (view && srcIos && containerView) {
1162
+ const sourceFrame = srcIos.convertRectToView(srcIos.bounds, containerView);
1163
+ const bounds = view.bounds;
1164
+ if (bounds.size.width > 0 && bounds.size.height > 0 && sourceFrame.size.width > 0 && sourceFrame.size.height > 0) {
1165
+ // Anchor the modal's transform on the *internal* matched
1166
+ // element (e.g. the album art inside the modal) so that the
1167
+ // modal and the matched element converge along the same
1168
+ // trajectory to the source thumbnail. Without this, the modal
1169
+ // scales around its own center while the matched-element
1170
+ // snapshot flies separately to source — making the two visibly
1171
+ // drift apart mid-spring.
1172
+ //
1173
+ // Pick a uniform scale that takes the modal's matched element
1174
+ // to the source's size. For square album art (both sides) this
1175
+ // is exact; for slightly off-square sources (e.g. 360×380) we
1176
+ // match width and let the small remainder be hidden by the
1177
+ // fade-out.
1178
+ const destSharedFrameInModal = destSharedIos ? destSharedIos.convertRectToView(destSharedIos.bounds, view) : null;
1179
+ const sx = sourceFrame.size.width / bounds.size.width;
1180
+ const sy = sourceFrame.size.height / bounds.size.height;
1181
+ const targetCx = sourceFrame.origin.x + sourceFrame.size.width / 2;
1182
+ const targetCy = sourceFrame.origin.y + sourceFrame.size.height / 2;
1183
+ const modalCx = bounds.size.width / 2;
1184
+ const modalCy = bounds.size.height / 2;
1185
+ let tx;
1186
+ let ty;
1187
+ if (destSharedFrameInModal && destSharedFrameInModal.size.width > 0 && destSharedFrameInModal.size.height > 0) {
1188
+ // Place the internal album art's center on the source's
1189
+ // center. After scaling around modal center, internal art's
1190
+ // visual center = modalCenter + (internalArtCenter - modalCenter) * scale + translation.
1191
+ const internalCx = destSharedFrameInModal.origin.x + destSharedFrameInModal.size.width / 2;
1192
+ const internalCy = destSharedFrameInModal.origin.y + destSharedFrameInModal.size.height / 2;
1193
+ tx = targetCx - modalCx - (internalCx - modalCx) * sx;
1194
+ ty = targetCy - modalCy - (internalCy - modalCy) * sy;
1195
+ }
1196
+ else {
1197
+ // Fallback: align modal center on source center.
1198
+ tx = targetCx - modalCx;
1199
+ ty = targetCy - modalCy;
1200
+ }
1201
+ targetTransform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(tx, ty), CGAffineTransformMakeScale(sx, sy));
1202
+ }
1203
+ }
1204
+ // Build a snapshot fly-back for each shared element so the album
1205
+ // art (etc.) does a real shared-element transition to its source
1206
+ // frame in parallel with the destination view's shrink+fade.
1207
+ // Without this, the image rides along with the morphing view and
1208
+ // lands at a visually offset position rather than precisely back
1209
+ // at the source thumbnail.
1210
+ const sharedSnapshots = [];
1211
+ if (containerView) {
1212
+ for (const presented of state.instance.sharedElements?.presented || []) {
1213
+ const destSharedView = presented.view?.ios;
1214
+ const tag = presented.view?.sharedTransitionTag;
1215
+ if (!destSharedView || !tag)
1216
+ continue;
1217
+ const sourceShared = state.instance.sharedElements?.presenting?.find?.((p) => p.view.sharedTransitionTag === tag);
1218
+ const srcSharedView = sourceShared?.view?.ios;
1219
+ if (!srcSharedView)
1220
+ continue;
1221
+ const startFrame = destSharedView.convertRectToView(destSharedView.bounds, containerView);
1222
+ const endFrame = srcSharedView.convertRectToView(srcSharedView.bounds, containerView);
1223
+ if (startFrame.size.width <= 0 || endFrame.size.width <= 0)
1224
+ continue;
1225
+ const snap = UIImageView.alloc().init();
1226
+ if (destSharedView instanceof UIImageView && destSharedView.image) {
1227
+ snap.image = destSharedView.image;
1228
+ snap.contentMode = destSharedView.contentMode;
1229
+ snap.tintColor = destSharedView.tintColor;
1230
+ }
1231
+ else {
1232
+ try {
1233
+ snap.image = iOSUtils.snapshotView(presented.view.ios, Screen.mainScreen.scale);
1234
+ }
1235
+ catch (e) {
1236
+ continue;
1237
+ }
1238
+ }
1239
+ snap.clipsToBounds = true;
1240
+ snap.layer.cornerRadius = destSharedView.layer?.cornerRadius || 0;
1241
+ snap.frame = startFrame;
1242
+ containerView.addSubview(snap);
1243
+ // Hide the destination shared element so we don't see it
1244
+ // shrinking inside the morphing view at the same time the
1245
+ // snapshot is flying back to source — that would double up.
1246
+ destSharedView.alpha = 0;
1247
+ sharedSnapshots.push({
1248
+ snap,
1249
+ endFrame,
1250
+ endCornerRadius: srcSharedView.layer?.cornerRadius || 0,
1251
+ srcSharedView,
1252
+ });
1253
+ }
1254
+ }
1255
+ // Identify which source NS views have a matching fly-back snapshot.
1256
+ // Those sources stay at alpha 0 through the spring and are restored
1257
+ // inside finalize(), so the snapshot doesn't overlay an already-
1258
+ // visible source mid-flight (which looks like two images for a beat).
1259
+ const snapshottedSources = new Set();
1260
+ for (const entry of sharedSnapshots) {
1261
+ if (entry.srcSharedView)
1262
+ snapshottedSources.add(entry.srcSharedView);
1263
+ }
1264
+ // Source-only orphan views (album thumbnails, badges, etc.) were
1265
+ // already restored to their opacity by the gesture handler at morph
1266
+ // engagement, so we don't need fade-in snapshots here — they're
1267
+ // already visible behind the morphing modal.
1268
+ let didFinalize = false;
1269
+ const finalize = () => {
1270
+ if (didFinalize)
1271
+ return;
1272
+ didFinalize = true;
1273
+ // Detach the imageSourceChange listeners that were attached during
1274
+ // PRESENT — the destination View is about to be torn down.
1275
+ for (const presented of state.instance.sharedElements?.presented || []) {
1276
+ if (presented.imageSourceChangeListener) {
1277
+ presented.view.off('imageSourceChange', presented.imageSourceChangeListener);
1278
+ presented.imageSourceChangeListener = null;
1279
+ }
1280
+ }
1281
+ // Restore the snapshotted sources (held at alpha 0 through the
1282
+ // spring) immediately before removing the snapshot, so the
1283
+ // snapshot's last frame and the source's first visible frame
1284
+ // coincide exactly — no double-image, no gap.
1285
+ for (const entry of sharedSnapshots) {
1286
+ const srcSharedView = entry.srcSharedView;
1287
+ if (srcSharedView) {
1288
+ const nsView = state.instance.sharedElements?.presenting?.find?.((p) => p.view?.ios === srcSharedView)?.view;
1289
+ srcSharedView.alpha = nsView ? nsView.opacity : 1;
1290
+ }
1291
+ }
1292
+ for (const { snap } of sharedSnapshots) {
1293
+ snap.removeFromSuperview();
1294
+ }
1295
+ // Independent (orphan) views were restored at gesture engagement,
1296
+ // so they're already visible. Just tear down any leftover present-
1297
+ // phase snapshots that weren't removed in present cleanup, and
1298
+ // ensure alpha is set from NS opacity for safety in case the
1299
+ // engagement code path was bypassed.
1300
+ for (const independent of state.instance?.sharedElements?.independent || []) {
1301
+ if (independent.view?.ios) {
1302
+ independent.view.ios.alpha = independent.view.opacity;
1303
+ }
1304
+ independent.snapshot?.removeFromSuperview();
1305
+ }
1306
+ if (view) {
1307
+ view.transform = CGAffineTransformIdentity;
1308
+ view.alpha = 1;
1309
+ }
1310
+ // Remove the sibling shadow view if interactive engagement added one.
1311
+ removeInteractiveDismissShadow(view);
1312
+ SharedTransition.finishState(state.instance.id);
1313
+ if (interactiveState.transitionContext) {
1314
+ interactiveState.transitionContext.finishInteractiveTransition();
1315
+ interactiveState.transitionContext.completeTransition(true);
1316
+ }
1317
+ SharedTransition.notifyEvent(SharedTransition.finishedEvent, {
1318
+ id: state?.instance?.id,
1319
+ type,
1320
+ action: 'interactiveFinish',
1321
+ });
1322
+ };
1323
+ if (view && targetTransform) {
1324
+ const shadowViewToAnimate = view.__sharedTransitionShadowView;
1325
+ iOSUtils.animateWithSpring({
1326
+ animations: () => {
1327
+ view.transform = targetTransform;
1328
+ view.alpha = 0;
1329
+ // Drive the sibling shadow view through the same spring so it
1330
+ // shrinks + translates with the modal as it morphs to the
1331
+ // source. Also fade it out so it doesn't linger behind the
1332
+ // finalizing snapshot.
1333
+ if (shadowViewToAnimate) {
1334
+ shadowViewToAnimate.transform = targetTransform;
1335
+ shadowViewToAnimate.alpha = 0;
1336
+ }
1337
+ // Restore source-side element alphas IN PARALLEL with the
1338
+ // destination's morph + fade — but skip sources that have
1339
+ // a flying snapshot. Those are held at alpha 0 and
1340
+ // revealed by finalize() right before the snapshot is
1341
+ // removed, so the user never sees both the snapshot AND
1342
+ // the source visible at the same time.
1343
+ for (const v of state.instance.sharedElements?._allPresentingViews || []) {
1344
+ if (v?.ios && !snapshottedSources.has(v.ios)) {
1345
+ v.ios.alpha = v.opacity;
1346
+ }
1347
+ }
1348
+ // Source-only orphan views were already restored at
1349
+ // engagement; nothing more to do for them here.
1350
+ // Fly each shared-element snapshot to its source frame.
1351
+ // Rides the same spring so the image lands precisely back
1352
+ // at the source position as the destination view fades.
1353
+ for (const { snap, endFrame, endCornerRadius } of sharedSnapshots) {
1354
+ snap.frame = endFrame;
1355
+ snap.layer.cornerRadius = endCornerRadius;
1356
+ }
1357
+ },
1358
+ completion: () => finalize(),
1359
+ });
1360
+ // Safety: ensure finalize runs even if the animation completion
1361
+ // is dropped (e.g. interrupted by another gesture).
1362
+ setTimeout(finalize, 800);
1363
+ }
1364
+ else {
1365
+ // No target transform; ensure sources are still restored.
1366
+ for (const v of state.instance.sharedElements?._allPresentingViews || []) {
1367
+ if (v?.ios)
1368
+ v.ios.alpha = v.opacity;
1369
+ }
1370
+ finalize();
1371
+ }
1372
+ return;
1373
+ }
516
1374
  if (state?.instance && interactiveState?.added && interactiveState?.propertyAnimator) {
517
1375
  interactiveState.propertyAnimator.reversed = false;
518
1376
  const duration = isNumber(state.pageReturn?.duration) ? state.pageReturn?.duration / 1000 : CORE_ANIMATION_DEFAULTS.duration;
519
1377
  interactiveState.propertyAnimator.continueAnimationWithTimingParametersDurationFactor(null, duration);
520
1378
  setTimeout(() => {
1379
+ // Restore alpha on every source view we hid (including duplicates) so
1380
+ // the source page is visible if shown again.
1381
+ for (const sourceView of state.instance.sharedElements._allPresentingViews || []) {
1382
+ if (sourceView?.ios) {
1383
+ sourceView.ios.alpha = sourceView.opacity;
1384
+ }
1385
+ }
521
1386
  for (const presenting of state.instance.sharedElements.presenting) {
522
- presenting.view.opacity = presenting.startOpacity;
523
1387
  presenting.snapshot.removeFromSuperview();
524
1388
  }
1389
+ for (const presented of state.instance.sharedElements.presented) {
1390
+ if (presented.imageSourceChangeListener) {
1391
+ presented.view.off('imageSourceChange', presented.imageSourceChangeListener);
1392
+ presented.imageSourceChangeListener = null;
1393
+ }
1394
+ }
1395
+ // Restore alpha on independent (orphan) source views and tear down
1396
+ // their snapshots. Without this, source-only orphans (any non-matched
1397
+ // sharedTransitionTag on the source page) stay at alpha 0 forever,
1398
+ // leaving the page visibly blank where they used to be. The non-morph
1399
+ // interactive path drives a propertyAnimator instead of running the
1400
+ // dismiss snapshot/animation rig, so the standard cleanup doesn't run.
1401
+ for (const ind of state.instance.sharedElements.independent) {
1402
+ if (ind.view?.ios) {
1403
+ ind.view.ios.alpha = ind.view.opacity;
1404
+ }
1405
+ ind.snapshot?.removeFromSuperview();
1406
+ }
525
1407
  SharedTransition.finishState(state.instance.id);
526
1408
  interactiveState.propertyAnimator = null;
527
1409
  interactiveState.added = false;