@akylas/nativescript 8.5.10 → 8.6.3

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 (326) hide show
  1. package/abortcontroller/index.d.ts +1 -1
  2. package/abortcontroller/index.js +4 -4
  3. package/abortcontroller/index.js.map +1 -1
  4. package/accessibility/accessibility-properties.js +1 -1
  5. package/accessibility/accessibility-properties.js.map +1 -1
  6. package/accessibility/font-scale-common.js +1 -1
  7. package/accessibility/font-scale-common.js.map +1 -1
  8. package/accessibility/index.android.js +24 -6
  9. package/accessibility/index.android.js.map +1 -1
  10. package/animation-frame/index.js +12 -1
  11. package/animation-frame/index.js.map +1 -1
  12. package/application/application-common.d.ts +2 -1
  13. package/application/application-common.js +4 -0
  14. package/application/application-common.js.map +1 -1
  15. package/application/application-interfaces.d.ts +6 -0
  16. package/application/application.android.d.ts +4 -0
  17. package/application/application.android.js +7 -4
  18. package/application/application.android.js.map +1 -1
  19. package/application/application.d.ts +18 -0
  20. package/application/application.ios.d.ts +4 -1
  21. package/application/application.ios.js +53 -6
  22. package/application/application.ios.js.map +1 -1
  23. package/application-settings/index.android.d.ts +2 -0
  24. package/application-settings/index.android.js +19 -0
  25. package/application-settings/index.android.js.map +1 -1
  26. package/application-settings/index.d.ts +12 -0
  27. package/application-settings/index.ios.d.ts +2 -0
  28. package/application-settings/index.ios.js +11 -0
  29. package/application-settings/index.ios.js.map +1 -1
  30. package/color/color-common.d.ts +14 -13
  31. package/color/color-common.js +2 -1
  32. package/color/color-common.js.map +1 -1
  33. package/color/index.android.d.ts +1 -1
  34. package/color/index.android.js +1 -1
  35. package/color/index.android.js.map +1 -1
  36. package/color/index.ios.d.ts +1 -1
  37. package/color/index.ios.js +1 -1
  38. package/color/index.ios.js.map +1 -1
  39. package/config/config.interface.d.ts +20 -6
  40. package/core-types/index.d.ts +7 -0
  41. package/core-types/index.js +7 -0
  42. package/core-types/index.js.map +1 -1
  43. package/css/CSS3Parser.js.map +1 -1
  44. package/css/system-classes.d.ts +2 -2
  45. package/data/observable/index.js.map +1 -1
  46. package/debugger/InspectorBackendCommands.ios.js.map +1 -1
  47. package/debugger/webinspector-css.ios.js.map +1 -1
  48. package/debugger/webinspector-dom.ios.js.map +1 -1
  49. package/debugger/webinspector-network.ios.js.map +1 -1
  50. package/file-system/file-system-access.android.js +10 -10
  51. package/file-system/file-system-access.android.js.map +1 -1
  52. package/file-system/index.d.ts +3 -3
  53. package/file-system/index.js +4 -4
  54. package/file-system/index.js.map +1 -1
  55. package/global-types.d.ts +1 -1
  56. package/image-asset/image-asset-common.js +13 -10
  57. package/image-asset/image-asset-common.js.map +1 -1
  58. package/image-asset/index.android.js +2 -2
  59. package/image-asset/index.android.js.map +1 -1
  60. package/image-asset/index.ios.js +1 -1
  61. package/image-asset/index.ios.js.map +1 -1
  62. package/package.json +1 -1
  63. package/platform/common.d.ts +8 -0
  64. package/platform/common.js +12 -0
  65. package/platform/common.js.map +1 -0
  66. package/platform/index.android.d.ts +1 -7
  67. package/platform/index.android.js +2 -6
  68. package/platform/index.android.js.map +1 -1
  69. package/platform/index.d.ts +5 -6
  70. package/platform/index.ios.d.ts +1 -7
  71. package/platform/index.ios.js +2 -6
  72. package/platform/index.ios.js.map +1 -1
  73. package/platforms/android/native-api-usage.json +6 -0
  74. package/platforms/android/widgets-release.aar +0 -0
  75. package/platforms/ios/TNSWidgets.xcframework/Info.plist +7 -7
  76. package/platforms/ios/TNSWidgets.xcframework/ios-arm64/TNSWidgets.framework/Info.plist +0 -0
  77. package/platforms/ios/TNSWidgets.xcframework/ios-arm64/TNSWidgets.framework/TNSWidgets +0 -0
  78. package/platforms/ios/TNSWidgets.xcframework/ios-arm64/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/DWARF/TNSWidgets +0 -0
  79. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/TNSWidgets.framework/Resources/Info.plist +7 -7
  80. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/TNSWidgets.framework/TNSWidgets +0 -0
  81. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/TNSWidgets.framework/Versions/A/Resources/Info.plist +7 -7
  82. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/TNSWidgets.framework/Versions/A/TNSWidgets +0 -0
  83. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/TNSWidgets.framework/Versions/Current/TNSWidgets +0 -0
  84. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/DWARF/TNSWidgets +0 -0
  85. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/Relocations/aarch64/TNSWidgets.yml +82 -0
  86. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-maccatalyst/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/Relocations/x86_64/TNSWidgets.yml +82 -0
  87. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/TNSWidgets.framework/Info.plist +0 -0
  88. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/TNSWidgets.framework/TNSWidgets +0 -0
  89. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/TNSWidgets.framework/_CodeSignature/CodeResources +1 -1
  90. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/DWARF/TNSWidgets +0 -0
  91. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/Relocations/aarch64/TNSWidgets.yml +82 -0
  92. package/platforms/ios/TNSWidgets.xcframework/ios-arm64_x86_64-simulator/dSYMs/TNSWidgets.framework.dSYM/Contents/Resources/Relocations/x86_64/TNSWidgets.yml +82 -0
  93. package/platforms/ios/src/UIView+NativeScript.h +2 -0
  94. package/platforms/ios/src/UIView+NativeScript.m +15 -0
  95. package/profiling/index.js +2 -2
  96. package/profiling/index.js.map +1 -1
  97. package/ui/action-bar/action-bar-common.js.map +1 -1
  98. package/ui/action-bar/index.android.js +3 -2
  99. package/ui/action-bar/index.android.js.map +1 -1
  100. package/ui/action-bar/index.ios.js +4 -0
  101. package/ui/action-bar/index.ios.js.map +1 -1
  102. package/ui/activity-indicator/activity-indicator-common.js.map +1 -1
  103. package/ui/activity-indicator/index.android.js +6 -5
  104. package/ui/activity-indicator/index.android.js.map +1 -1
  105. package/ui/animation/index.ios.d.ts +3 -0
  106. package/ui/animation/index.ios.js +255 -84
  107. package/ui/animation/index.ios.js.map +1 -1
  108. package/ui/builder/xml2ui.js.map +1 -1
  109. package/ui/button/button-common.js.map +1 -1
  110. package/ui/button/index.android.js +1 -1
  111. package/ui/button/index.android.js.map +1 -1
  112. package/ui/button/index.ios.d.ts +1 -0
  113. package/ui/button/index.ios.js +27 -11
  114. package/ui/button/index.ios.js.map +1 -1
  115. package/ui/content-view/index.js +1 -1
  116. package/ui/content-view/index.js.map +1 -1
  117. package/ui/core/view/index.android.d.ts +16 -3
  118. package/ui/core/view/index.android.js +58 -46
  119. package/ui/core/view/index.android.js.map +1 -1
  120. package/ui/core/view/index.d.ts +2 -2
  121. package/ui/core/view/index.ios.d.ts +2 -2
  122. package/ui/core/view/index.ios.js +123 -56
  123. package/ui/core/view/index.ios.js.map +1 -1
  124. package/ui/core/view/view-common.d.ts +5 -4
  125. package/ui/core/view/view-common.js +20 -3
  126. package/ui/core/view/view-common.js.map +1 -1
  127. package/ui/core/view/view-helper/index.d.ts +2 -1
  128. package/ui/core/view/view-helper/index.ios.d.ts +1 -0
  129. package/ui/core/view/view-helper/index.ios.js +8 -5
  130. package/ui/core/view/view-helper/index.ios.js.map +1 -1
  131. package/ui/core/view-base/index.d.ts +11 -4
  132. package/ui/core/view-base/index.js +76 -26
  133. package/ui/core/view-base/index.js.map +1 -1
  134. package/ui/date-picker/date-picker-common.js.map +1 -1
  135. package/ui/dialogs/dialogs-common.js +3 -3
  136. package/ui/dialogs/dialogs-common.js.map +1 -1
  137. package/ui/editable-text-base/editable-text-base-common.d.ts +2 -0
  138. package/ui/editable-text-base/editable-text-base-common.js +6 -0
  139. package/ui/editable-text-base/editable-text-base-common.js.map +1 -1
  140. package/ui/editable-text-base/index.android.d.ts +2 -3
  141. package/ui/editable-text-base/index.android.js +39 -13
  142. package/ui/editable-text-base/index.android.js.map +1 -1
  143. package/ui/editable-text-base/index.ios.js +7 -1
  144. package/ui/editable-text-base/index.ios.js.map +1 -1
  145. package/ui/frame/fragment.transitions.android.js +9 -6
  146. package/ui/frame/fragment.transitions.android.js.map +1 -1
  147. package/ui/frame/frame-common.js +17 -6
  148. package/ui/frame/frame-common.js.map +1 -1
  149. package/ui/frame/index.android.js +53 -18
  150. package/ui/frame/index.android.js.map +1 -1
  151. package/ui/frame/index.ios.js.map +1 -1
  152. package/ui/gestures/gestures-common.d.ts +232 -7
  153. package/ui/gestures/gestures-common.js +98 -4
  154. package/ui/gestures/gestures-common.js.map +1 -1
  155. package/ui/gestures/index.d.ts +2 -289
  156. package/ui/gestures/touch-manager.js +2 -2
  157. package/ui/gestures/touch-manager.js.map +1 -1
  158. package/ui/html-view/html-view-common.js.map +1 -1
  159. package/ui/image/image-common.js +1 -1
  160. package/ui/image/image-common.js.map +1 -1
  161. package/ui/image-cache/image-cache-common.js.map +1 -1
  162. package/ui/image-cache/index.ios.js +13 -13
  163. package/ui/image-cache/index.ios.js.map +1 -1
  164. package/ui/index.d.ts +1 -1
  165. package/ui/index.js +1 -1
  166. package/ui/index.js.map +1 -1
  167. package/ui/label/index.android.d.ts +3 -3
  168. package/ui/label/index.android.js +1 -5
  169. package/ui/label/index.android.js.map +1 -1
  170. package/ui/label/index.ios.d.ts +1 -0
  171. package/ui/label/index.ios.js +30 -8
  172. package/ui/label/index.ios.js.map +1 -1
  173. package/ui/layouts/absolute-layout/absolute-layout-common.js.map +1 -1
  174. package/ui/layouts/dock-layout/dock-layout-common.js +1 -1
  175. package/ui/layouts/dock-layout/dock-layout-common.js.map +1 -1
  176. package/ui/layouts/flexbox-layout/flexbox-layout-common.js +5 -5
  177. package/ui/layouts/flexbox-layout/flexbox-layout-common.js.map +1 -1
  178. package/ui/layouts/grid-layout/grid-layout-common.d.ts +7 -2
  179. package/ui/layouts/grid-layout/grid-layout-common.js +32 -6
  180. package/ui/layouts/grid-layout/grid-layout-common.js.map +1 -1
  181. package/ui/layouts/grid-layout/index.android.d.ts +9 -3
  182. package/ui/layouts/grid-layout/index.android.js +69 -38
  183. package/ui/layouts/grid-layout/index.android.js.map +1 -1
  184. package/ui/layouts/layout-base-common.js +12 -1
  185. package/ui/layouts/layout-base-common.js.map +1 -1
  186. package/ui/layouts/layout-base.android.js +3 -0
  187. package/ui/layouts/layout-base.android.js.map +1 -1
  188. package/ui/layouts/root-layout/index.ios.js +7 -2
  189. package/ui/layouts/root-layout/index.ios.js.map +1 -1
  190. package/ui/layouts/root-layout/root-layout-common.js.map +1 -1
  191. package/ui/layouts/stack-layout/stack-layout-common.js +1 -1
  192. package/ui/layouts/stack-layout/stack-layout-common.js.map +1 -1
  193. package/ui/layouts/wrap-layout/wrap-layout-common.js +3 -3
  194. package/ui/layouts/wrap-layout/wrap-layout-common.js.map +1 -1
  195. package/ui/list-picker/index.ios.js +1 -7
  196. package/ui/list-picker/index.ios.js.map +1 -1
  197. package/ui/list-picker/list-picker-common.js.map +1 -1
  198. package/ui/list-view/index.android.js.map +1 -1
  199. package/ui/list-view/index.ios.js.map +1 -1
  200. package/ui/list-view/list-view-common.js.map +1 -1
  201. package/ui/page/index.android.js +4 -2
  202. package/ui/page/index.android.js.map +1 -1
  203. package/ui/page/index.d.ts +0 -4
  204. package/ui/page/index.ios.d.ts +0 -2
  205. package/ui/page/index.ios.js +28 -25
  206. package/ui/page/index.ios.js.map +1 -1
  207. package/ui/page/page-common.d.ts +1 -1
  208. package/ui/page/page-common.js +10 -4
  209. package/ui/page/page-common.js.map +1 -1
  210. package/ui/placeholder/index.android.js.map +1 -1
  211. package/ui/progress/progress-common.js.map +1 -1
  212. package/ui/proxy-view-container/index.js.map +1 -1
  213. package/ui/repeater/index.js.map +1 -1
  214. package/ui/scroll-view/index.android.d.ts +1 -1
  215. package/ui/scroll-view/index.android.js +10 -6
  216. package/ui/scroll-view/index.android.js.map +1 -1
  217. package/ui/scroll-view/index.ios.d.ts +1 -2
  218. package/ui/scroll-view/index.ios.js +6 -8
  219. package/ui/scroll-view/index.ios.js.map +1 -1
  220. package/ui/scroll-view/scroll-view-common.d.ts +3 -5
  221. package/ui/scroll-view/scroll-view-common.js +23 -25
  222. package/ui/scroll-view/scroll-view-common.js.map +1 -1
  223. package/ui/search-bar/index.android.js +12 -1
  224. package/ui/search-bar/index.android.js.map +1 -1
  225. package/ui/search-bar/search-bar-common.js +1 -1
  226. package/ui/search-bar/search-bar-common.js.map +1 -1
  227. package/ui/segmented-bar/index.android.js +3 -2
  228. package/ui/segmented-bar/index.android.js.map +1 -1
  229. package/ui/segmented-bar/segmented-bar-common.js.map +1 -1
  230. package/ui/slider/slider-common.js +3 -3
  231. package/ui/slider/slider-common.js.map +1 -1
  232. package/ui/styling/background-common.d.ts +5 -4
  233. package/ui/styling/background-common.js +3 -0
  234. package/ui/styling/background-common.js.map +1 -1
  235. package/ui/styling/background.d.ts +13 -4
  236. package/ui/styling/background.ios.d.ts +26 -0
  237. package/ui/styling/background.ios.js +665 -368
  238. package/ui/styling/background.ios.js.map +1 -1
  239. package/ui/styling/box-shadow.d.ts +1 -0
  240. package/ui/styling/box-shadow.js.map +1 -1
  241. package/ui/styling/css-selector.js.map +1 -1
  242. package/ui/styling/css-shadow.d.ts +4 -4
  243. package/ui/styling/css-shadow.js +7 -75
  244. package/ui/styling/css-shadow.js.map +1 -1
  245. package/ui/styling/css-stroke.d.ts +12 -0
  246. package/ui/styling/css-stroke.js +19 -0
  247. package/ui/styling/css-stroke.js.map +1 -0
  248. package/ui/styling/css-utils.d.ts +7 -1
  249. package/ui/styling/css-utils.js +52 -0
  250. package/ui/styling/css-utils.js.map +1 -1
  251. package/ui/styling/font-common.d.ts +1 -1
  252. package/ui/styling/font-common.js +18 -11
  253. package/ui/styling/font-common.js.map +1 -1
  254. package/ui/styling/font-interfaces.d.ts +1 -1
  255. package/ui/styling/font.android.d.ts +0 -1
  256. package/ui/styling/font.android.js +9 -15
  257. package/ui/styling/font.android.js.map +1 -1
  258. package/ui/styling/font.d.ts +2 -2
  259. package/ui/styling/font.ios.js +15 -11
  260. package/ui/styling/font.ios.js.map +1 -1
  261. package/ui/styling/style/index.d.ts +8 -4
  262. package/ui/styling/style/index.js.map +1 -1
  263. package/ui/styling/style-properties.js +12 -2
  264. package/ui/styling/style-properties.js.map +1 -1
  265. package/ui/styling/style-scope.d.ts +1 -1
  266. package/ui/styling/style-scope.js +4 -4
  267. package/ui/styling/style-scope.js.map +1 -1
  268. package/ui/switch/switch-common.js.map +1 -1
  269. package/ui/tab-view/index.android.js +8 -4
  270. package/ui/tab-view/index.android.js.map +1 -1
  271. package/ui/tab-view/index.ios.js.map +1 -1
  272. package/ui/tab-view/tab-view-common.js +2 -2
  273. package/ui/tab-view/tab-view-common.js.map +1 -1
  274. package/ui/text-base/formatted-string.d.ts +3 -1
  275. package/ui/text-base/formatted-string.js +8 -0
  276. package/ui/text-base/formatted-string.js.map +1 -1
  277. package/ui/text-base/index.android.d.ts +5 -2
  278. package/ui/text-base/index.android.js +55 -37
  279. package/ui/text-base/index.android.js.map +1 -1
  280. package/ui/text-base/index.d.ts +16 -3
  281. package/ui/text-base/index.ios.d.ts +2 -2
  282. package/ui/text-base/index.ios.js +16 -15
  283. package/ui/text-base/index.ios.js.map +1 -1
  284. package/ui/text-base/span.d.ts +3 -1
  285. package/ui/text-base/span.js +6 -0
  286. package/ui/text-base/span.js.map +1 -1
  287. package/ui/text-base/text-base-common.d.ts +10 -4
  288. package/ui/text-base/text-base-common.js +33 -5
  289. package/ui/text-base/text-base-common.js.map +1 -1
  290. package/ui/text-field/index.android.d.ts +5 -0
  291. package/ui/text-field/index.android.js +36 -16
  292. package/ui/text-field/index.android.js.map +1 -1
  293. package/ui/text-field/text-field-common.js.map +1 -1
  294. package/ui/text-view/index.android.js.map +1 -1
  295. package/ui/text-view/index.ios.js.map +1 -1
  296. package/ui/time-picker/time-picker-common.js +8 -2
  297. package/ui/time-picker/time-picker-common.js.map +1 -1
  298. package/ui/transition/index.d.ts +1 -0
  299. package/ui/transition/page-transition.android.d.ts +5 -2
  300. package/ui/transition/page-transition.android.js +59 -19
  301. package/ui/transition/page-transition.android.js.map +1 -1
  302. package/ui/transition/page-transition.d.ts +3 -1
  303. package/ui/transition/shared-transition.js +3 -3
  304. package/ui/transition/shared-transition.js.map +1 -1
  305. package/ui/utils.d.ts +16 -19
  306. package/ui/utils.ios.d.ts +11 -10
  307. package/ui/utils.ios.js +37 -37
  308. package/ui/utils.ios.js.map +1 -1
  309. package/ui/web-view/web-view-common.js.map +1 -1
  310. package/utils/android/index.js +14 -2
  311. package/utils/android/index.js.map +1 -1
  312. package/utils/common.d.ts +3 -1
  313. package/utils/common.js +5 -1
  314. package/utils/common.js.map +1 -1
  315. package/utils/debug.js +1 -1
  316. package/utils/debug.js.map +1 -1
  317. package/utils/index.android.js +5 -3
  318. package/utils/index.android.js.map +1 -1
  319. package/utils/index.d.ts +2 -2
  320. package/utils/ios/index.d.ts +0 -1
  321. package/utils/ios/index.js +0 -65
  322. package/utils/ios/index.js.map +1 -1
  323. package/utils/native-helper.d.ts +0 -7
  324. package/utils/platform-check.js +1 -1
  325. package/utils/platform-check.js.map +1 -1
  326. package/xhr/index.js.map +1 -1
@@ -1,12 +1,12 @@
1
1
  import { LinearGradient } from './linear-gradient';
2
- import { Color } from '../../color';
3
- import { iOSNativeHelper, isDataURI, isFileOrResourcePath, layout } from '../../utils';
2
+ import { Screen } from '../../platform';
3
+ import { isDataURI, isFileOrResourcePath, layout } from '../../utils';
4
4
  import { ios as iosViewUtils } from '../utils';
5
5
  import { ImageSource } from '../../image-source';
6
6
  import { parse as cssParse } from '../../css-value';
7
- import { Length } from './style-properties';
8
7
  export * from './background-common';
9
8
  const clearCGColor = UIColor.clearColor.CGColor;
9
+ const uriPattern = /url\(('|")(.*?)\1\)/;
10
10
  const symbolUrl = Symbol('backgroundImageUrl');
11
11
  export var CacheMode;
12
12
  (function (CacheMode) {
@@ -20,59 +20,262 @@ export var ios;
20
20
  if (!nativeView) {
21
21
  return;
22
22
  }
23
- if (background.clearFlags & 2 /* BackgroundClearFlags.CLEAR_BOX_SHADOW */) {
24
- // clear box shadow if it has been removed!
25
- view.setProperty('clipToBounds', true);
26
- clearBoxShadow(nativeView);
23
+ // Unset this in case another layer handles background color (e.g. gradient)
24
+ nativeView.layer.backgroundColor = null;
25
+ // Cleanup of previous values
26
+ clearBackgroundVisualEffects(view);
27
+ // Borders, shadows, etc
28
+ drawBackgroundVisualEffects(view);
29
+ if (!background.image) {
30
+ callback(background?.color?.ios);
27
31
  }
28
- if (nativeView.hasNonUniformBorder) {
29
- unsubscribeFromScrollNotifications(view);
30
- clearNonUniformBorders(nativeView);
32
+ else {
33
+ if (!(background.image instanceof LinearGradient)) {
34
+ setUIColorFromImage(view, nativeView, callback, flip);
35
+ }
31
36
  }
32
- iosViewUtils.clearGradient(nativeView);
37
+ }
38
+ ios.createBackgroundUIColor = createBackgroundUIColor;
39
+ function drawBackgroundVisualEffects(view) {
40
+ const background = view.style.backgroundInternal;
41
+ const nativeView = view.nativeViewProtected;
42
+ const layer = nativeView.layer;
43
+ let needsLayerAdjustmentOnScroll = false;
44
+ // Add new gradient layer or update existing one
33
45
  if (background.image instanceof LinearGradient) {
34
- iosViewUtils.drawGradient(nativeView, background.image);
35
- }
36
- const hasNonUniformBorderWidths = background.hasBorderWidth() && !background.hasUniformBorder();
37
- const hasNonUniformBorderRadiuses = background.hasBorderRadius() && !background.hasUniformBorderRadius();
38
- if (background.hasUniformBorderColor() && (hasNonUniformBorderWidths || hasNonUniformBorderRadiuses)) {
39
- drawUniformColorNonUniformBorders(nativeView, background);
40
- subscribeForScrollNotifications(view);
46
+ if (!nativeView.gradientLayer) {
47
+ nativeView.gradientLayer = CAGradientLayer.new();
48
+ layer.insertSublayerAtIndex(nativeView.gradientLayer, 0);
49
+ }
50
+ iosViewUtils.drawGradient(nativeView, nativeView.gradientLayer, background.image);
51
+ needsLayerAdjustmentOnScroll = true;
41
52
  }
42
- else if (background.hasUniformBorder()) {
43
- const layer = nativeView.layer;
53
+ // Initialize clipping mask (usually for clip-path and non-uniform rounded borders)
54
+ maskLayerIfNeeded(nativeView, background);
55
+ if (background.hasUniformBorder()) {
44
56
  const borderColor = background.getUniformBorderColor();
45
- layer.borderColor = !borderColor ? undefined : borderColor.ios.CGColor;
57
+ layer.borderColor = borderColor?.ios?.CGColor;
46
58
  layer.borderWidth = layout.toDeviceIndependentPixels(background.getUniformBorderWidth());
47
- const renderSize = view.getActualSize() || { width: 0, height: 0 };
48
- const cornerRadius = layout.toDeviceIndependentPixels(background.getUniformBorderRadius());
49
- layer.cornerRadius = Math.min(Math.min(renderSize.width / 2, renderSize.height / 2), cornerRadius);
59
+ layer.cornerRadius = getUniformBorderRadius(view, layer.bounds);
50
60
  }
51
61
  else {
52
- drawNoRadiusNonUniformBorders(nativeView, background);
53
- subscribeForScrollNotifications(view);
62
+ drawNonUniformBorders(nativeView, background);
63
+ needsLayerAdjustmentOnScroll = true;
54
64
  }
55
- // Clip-path should be called after borders are applied.
56
- // It will eventually move them to different layer if uniform.
57
- if (background.clipPath) {
58
- drawClipPath(nativeView, background);
65
+ // Clip-path should be called after borders are applied
66
+ if (nativeView.maskType === iosViewUtils.LayerMask.CLIP_PATH && layer.mask instanceof CAShapeLayer) {
67
+ layer.mask.path = generateClipPath(view, layer.bounds);
59
68
  }
60
- if (!background.image || background.image instanceof LinearGradient) {
61
- const uiColor = background.color ? background.color.ios : undefined;
62
- callback(uiColor);
69
+ if (background.hasBoxShadow()) {
70
+ drawBoxShadow(view);
71
+ needsLayerAdjustmentOnScroll = true;
63
72
  }
64
- else {
65
- setUIColorFromImage(view, nativeView, callback, flip);
73
+ if (needsLayerAdjustmentOnScroll) {
74
+ registerAdjustLayersOnScrollListener(view);
66
75
  }
67
- if (background.hasBoxShadow()) {
68
- drawBoxShadow(nativeView, view, background.getBoxShadow(), background);
76
+ }
77
+ ios.drawBackgroundVisualEffects = drawBackgroundVisualEffects;
78
+ function clearBackgroundVisualEffects(view) {
79
+ const nativeView = view.nativeViewProtected;
80
+ if (!nativeView) {
81
+ return;
69
82
  }
70
- // reset clear flags
83
+ const background = view.style.backgroundInternal;
84
+ const hasGradientBackground = background.image && background.image instanceof LinearGradient;
85
+ // Remove mask if there is no clip path or non-uniform border with radius
86
+ let needsMask;
87
+ switch (nativeView.maskType) {
88
+ case iosViewUtils.LayerMask.BORDER:
89
+ needsMask = !background.hasUniformBorder() && background.hasBorderRadius();
90
+ break;
91
+ case iosViewUtils.LayerMask.CLIP_PATH:
92
+ needsMask = !!background.clipPath;
93
+ break;
94
+ default:
95
+ needsMask = false;
96
+ break;
97
+ }
98
+ if (!needsMask) {
99
+ clearLayerMask(nativeView);
100
+ }
101
+ // Clear box shadow if it's no longer needed
102
+ if (background.clearFlags & 2 /* BackgroundClearFlags.CLEAR_BOX_SHADOW */) {
103
+ clearBoxShadow(nativeView);
104
+ }
105
+ // Non-uniform borders cleanup
106
+ if (nativeView.hasNonUniformBorder) {
107
+ if (nativeView.hasNonUniformBorderColor && background.hasUniformBorderColor()) {
108
+ clearNonUniformColorBorders(nativeView);
109
+ }
110
+ if (background.hasUniformBorder()) {
111
+ clearNonUniformBorders(nativeView);
112
+ }
113
+ }
114
+ if (nativeView.gradientLayer && !hasGradientBackground) {
115
+ nativeView.gradientLayer.removeFromSuperlayer();
116
+ nativeView.gradientLayer = null;
117
+ }
118
+ // Force unset scroll listener
119
+ unregisterAdjustLayersOnScrollListener(view);
120
+ // Reset clear flags
71
121
  background.clearFlags = 0 /* BackgroundClearFlags.NONE */;
72
122
  }
73
- ios.createBackgroundUIColor = createBackgroundUIColor;
123
+ ios.clearBackgroundVisualEffects = clearBackgroundVisualEffects;
124
+ function generateShadowLayerPaths(view, bounds) {
125
+ const background = view.style.backgroundInternal;
126
+ const nativeView = view.nativeViewProtected;
127
+ const layer = nativeView.layer;
128
+ const boxShadow = background.getBoxShadow();
129
+ const spreadRadius = layout.toDeviceIndependentPixels(boxShadow.spreadRadius);
130
+ const { width, height } = bounds.size;
131
+ let innerPath, shadowPath;
132
+ // Generate more detailed paths if view has border radius
133
+ if (background.hasBorderRadius()) {
134
+ if (background.hasUniformBorder()) {
135
+ const cornerRadius = layer.cornerRadius;
136
+ const cappedRadius = getBorderCapRadius(cornerRadius, width / 2, height / 2);
137
+ const cappedOuterRadii = {
138
+ topLeft: cappedRadius,
139
+ topRight: cappedRadius,
140
+ bottomLeft: cappedRadius,
141
+ bottomRight: cappedRadius,
142
+ };
143
+ const cappedOuterRadiiWithSpread = {
144
+ topLeft: cappedRadius + spreadRadius,
145
+ topRight: cappedRadius + spreadRadius,
146
+ bottomLeft: cappedRadius + spreadRadius,
147
+ bottomRight: cappedRadius + spreadRadius,
148
+ };
149
+ innerPath = generateNonUniformBorderOuterClipPath(bounds, cappedOuterRadii);
150
+ shadowPath = generateNonUniformBorderOuterClipPath(bounds, cappedOuterRadiiWithSpread, spreadRadius);
151
+ }
152
+ else {
153
+ const outerTopLeftRadius = layout.toDeviceIndependentPixels(background.borderTopLeftRadius);
154
+ const outerTopRightRadius = layout.toDeviceIndependentPixels(background.borderTopRightRadius);
155
+ const outerBottomRightRadius = layout.toDeviceIndependentPixels(background.borderBottomRightRadius);
156
+ const outerBottomLeftRadius = layout.toDeviceIndependentPixels(background.borderBottomLeftRadius);
157
+ const topRadii = outerTopLeftRadius + outerTopRightRadius;
158
+ const rightRadii = outerTopRightRadius + outerBottomRightRadius;
159
+ const bottomRadii = outerBottomRightRadius + outerBottomLeftRadius;
160
+ const leftRadii = outerBottomLeftRadius + outerTopLeftRadius;
161
+ const cappedOuterRadii = {
162
+ topLeft: getBorderCapRadius(outerTopLeftRadius, (outerTopLeftRadius / topRadii) * width, (outerTopLeftRadius / leftRadii) * height),
163
+ topRight: getBorderCapRadius(outerTopRightRadius, (outerTopRightRadius / topRadii) * width, (outerTopRightRadius / rightRadii) * height),
164
+ bottomLeft: getBorderCapRadius(outerBottomLeftRadius, (outerBottomLeftRadius / bottomRadii) * width, (outerBottomLeftRadius / leftRadii) * height),
165
+ bottomRight: getBorderCapRadius(outerBottomRightRadius, (outerBottomRightRadius / bottomRadii) * width, (outerBottomRightRadius / rightRadii) * height),
166
+ };
167
+ // Add spread radius to corners that actually have radius as shadow has grown larger
168
+ // than view itself and needs to be rounded accordingly
169
+ const cappedOuterRadiiWithSpread = {
170
+ topLeft: cappedOuterRadii.topLeft > 0 ? cappedOuterRadii.topLeft + spreadRadius : cappedOuterRadii.topLeft,
171
+ topRight: cappedOuterRadii.topRight > 0 ? cappedOuterRadii.topRight + spreadRadius : cappedOuterRadii.topRight,
172
+ bottomLeft: cappedOuterRadii.bottomLeft > 0 ? cappedOuterRadii.bottomLeft + spreadRadius : cappedOuterRadii.bottomLeft,
173
+ bottomRight: cappedOuterRadii.bottomRight > 0 ? cappedOuterRadii.bottomRight + spreadRadius : cappedOuterRadii.bottomRight,
174
+ };
175
+ innerPath = generateNonUniformBorderOuterClipPath(bounds, cappedOuterRadii);
176
+ shadowPath = generateNonUniformBorderOuterClipPath(bounds, cappedOuterRadiiWithSpread, spreadRadius);
177
+ }
178
+ }
179
+ else {
180
+ innerPath = CGPathCreateWithRect(bounds, null);
181
+ shadowPath = CGPathCreateWithRect(CGRectInset(bounds, -spreadRadius, -spreadRadius), null);
182
+ }
183
+ return {
184
+ maskPath: generateShadowMaskPath(bounds, boxShadow, innerPath),
185
+ shadowPath,
186
+ };
187
+ }
188
+ ios.generateShadowLayerPaths = generateShadowLayerPaths;
189
+ function generateClipPath(view, bounds) {
190
+ const background = view.style.backgroundInternal;
191
+ const { origin, size } = bounds;
192
+ const position = {
193
+ left: origin.x,
194
+ top: origin.y,
195
+ bottom: size.height,
196
+ right: size.width,
197
+ };
198
+ if (position.right === 0 || position.bottom === 0) {
199
+ return;
200
+ }
201
+ let path;
202
+ const clipPath = background.clipPath;
203
+ const functionName = clipPath.substring(0, clipPath.indexOf('('));
204
+ const value = clipPath.replace(`${functionName}(`, '').replace(')', '');
205
+ switch (functionName) {
206
+ case 'rect':
207
+ path = rectPath(value, position);
208
+ break;
209
+ case 'inset':
210
+ path = insetPath(value, position);
211
+ break;
212
+ case 'circle':
213
+ path = circlePath(value, position);
214
+ break;
215
+ case 'ellipse':
216
+ path = ellipsePath(value, position);
217
+ break;
218
+ case 'polygon':
219
+ path = polygonPath(value, position);
220
+ break;
221
+ }
222
+ return path;
223
+ }
224
+ ios.generateClipPath = generateClipPath;
225
+ function getUniformBorderRadius(view, bounds) {
226
+ const background = view.style.backgroundInternal;
227
+ const { width, height } = bounds.size;
228
+ const cornerRadius = layout.toDeviceIndependentPixels(background.getUniformBorderRadius());
229
+ return Math.min(Math.min(width / 2, height / 2), cornerRadius);
230
+ }
231
+ ios.getUniformBorderRadius = getUniformBorderRadius;
232
+ function generateNonUniformBorderInnerClipRoundedPath(view, bounds) {
233
+ const background = view.style.backgroundInternal;
234
+ const cappedOuterRadii = calculateNonUniformBorderCappedRadii(bounds, background);
235
+ return generateNonUniformBorderInnerClipPath(bounds, background, cappedOuterRadii);
236
+ }
237
+ ios.generateNonUniformBorderInnerClipRoundedPath = generateNonUniformBorderInnerClipRoundedPath;
238
+ function generateNonUniformBorderOuterClipRoundedPath(view, bounds) {
239
+ const background = view.style.backgroundInternal;
240
+ const cappedOuterRadii = calculateNonUniformBorderCappedRadii(bounds, background);
241
+ return generateNonUniformBorderOuterClipPath(bounds, cappedOuterRadii);
242
+ }
243
+ ios.generateNonUniformBorderOuterClipRoundedPath = generateNonUniformBorderOuterClipRoundedPath;
244
+ function generateNonUniformMultiColorBorderRoundedPaths(view, bounds) {
245
+ const background = view.style.backgroundInternal;
246
+ return generateNonUniformMultiColorBorderPaths(bounds, background);
247
+ }
248
+ ios.generateNonUniformMultiColorBorderRoundedPaths = generateNonUniformMultiColorBorderRoundedPaths;
74
249
  })(ios || (ios = {}));
75
- function onScroll(args) {
250
+ function maskLayerIfNeeded(nativeView, background) {
251
+ const layer = nativeView.layer;
252
+ // Check if layer should be masked
253
+ if (!(layer.mask instanceof CAShapeLayer)) {
254
+ // Since layers can only accept up to a single mask at a time, clip path is given more priority
255
+ if (background.clipPath) {
256
+ nativeView.maskType = iosViewUtils.LayerMask.CLIP_PATH;
257
+ }
258
+ else if (!background.hasUniformBorder() && background.hasBorderRadius()) {
259
+ nativeView.maskType = iosViewUtils.LayerMask.BORDER;
260
+ }
261
+ else {
262
+ nativeView.maskType = null;
263
+ }
264
+ if (nativeView.maskType != null) {
265
+ nativeView.originalMask = layer.mask;
266
+ layer.mask = CAShapeLayer.new();
267
+ }
268
+ }
269
+ }
270
+ function clearLayerMask(nativeView) {
271
+ if (nativeView.outerShadowContainerLayer) {
272
+ nativeView.outerShadowContainerLayer.mask = null;
273
+ }
274
+ nativeView.layer.mask = nativeView.originalMask;
275
+ nativeView.originalMask = null;
276
+ nativeView.maskType = null;
277
+ }
278
+ function onBackgroundViewScroll(args) {
76
279
  const view = args.object;
77
280
  const nativeView = view.nativeViewProtected;
78
281
  if (nativeView instanceof UIScrollView) {
@@ -80,61 +283,62 @@ function onScroll(args) {
80
283
  }
81
284
  }
82
285
  function adjustLayersForScrollView(nativeView) {
83
- const layer = nativeView.borderLayer;
84
- if (layer instanceof CALayer) {
85
- // Compensates with transition for the background layers for scrolling in ScrollView based controls.
86
- CATransaction.begin();
87
- CATransaction.setValueForKey(kCFBooleanTrue, kCATransactionDisableActions);
88
- const offset = nativeView.contentOffset;
89
- const transform = {
90
- a: 1,
91
- b: 0,
92
- c: 0,
93
- d: 1,
94
- tx: offset.x,
95
- ty: offset.y,
96
- };
97
- layer.setAffineTransform(transform);
98
- if (nativeView.layer.mask) {
99
- nativeView.layer.mask.setAffineTransform(transform);
100
- }
101
- CATransaction.commit();
286
+ // Compensates with transition for the background layers for scrolling in ScrollView based controls.
287
+ CATransaction.begin();
288
+ CATransaction.setDisableActions(true);
289
+ const offset = nativeView.contentOffset;
290
+ const transform = {
291
+ a: 1,
292
+ b: 0,
293
+ c: 0,
294
+ d: 1,
295
+ tx: offset.x,
296
+ ty: offset.y,
297
+ };
298
+ if (nativeView.layer.mask) {
299
+ nativeView.layer.mask.setAffineTransform(transform);
300
+ }
301
+ // Nested layers
302
+ if (nativeView.gradientLayer) {
303
+ nativeView.gradientLayer.setAffineTransform(transform);
304
+ }
305
+ if (nativeView.borderLayer) {
306
+ nativeView.borderLayer.setAffineTransform(transform);
102
307
  }
308
+ if (nativeView.outerShadowContainerLayer) {
309
+ // Update bounds of shadow layer as it belongs to parent view
310
+ nativeView.outerShadowContainerLayer.bounds = nativeView.bounds;
311
+ nativeView.outerShadowContainerLayer.setAffineTransform(transform);
312
+ }
313
+ CATransaction.setDisableActions(false);
314
+ CATransaction.commit();
103
315
  }
104
- function unsubscribeFromScrollNotifications(view) {
316
+ function unregisterAdjustLayersOnScrollListener(view) {
105
317
  if (view.nativeViewProtected instanceof UIScrollView) {
106
- view.off('scroll', onScroll);
318
+ view.off('scroll', onBackgroundViewScroll);
107
319
  }
108
320
  }
109
- function subscribeForScrollNotifications(view) {
321
+ function registerAdjustLayersOnScrollListener(view) {
110
322
  if (view.nativeViewProtected instanceof UIScrollView) {
111
- view.on('scroll', onScroll);
323
+ view.off('scroll', onBackgroundViewScroll);
324
+ view.on('scroll', onBackgroundViewScroll);
112
325
  adjustLayersForScrollView(view.nativeViewProtected);
113
326
  }
114
327
  }
328
+ function clearNonUniformColorBorders(nativeView) {
329
+ if (nativeView.borderLayer) {
330
+ nativeView.borderLayer.mask = null;
331
+ nativeView.borderLayer.sublayers = null;
332
+ }
333
+ nativeView.hasNonUniformBorderColor = false;
334
+ }
115
335
  function clearNonUniformBorders(nativeView) {
116
336
  if (nativeView.borderLayer) {
117
337
  nativeView.borderLayer.removeFromSuperlayer();
338
+ nativeView.borderLayer = null;
118
339
  }
119
- if (nativeView.hasBorderMask) {
120
- nativeView.layer.mask = nativeView.borderOriginalMask;
121
- nativeView.hasBorderMask = false;
122
- nativeView.borderOriginalMask = null;
123
- }
124
- if (nativeView.topBorderLayer) {
125
- nativeView.topBorderLayer.removeFromSuperlayer();
126
- }
127
- if (nativeView.rightBorderLayer) {
128
- nativeView.rightBorderLayer.removeFromSuperlayer();
129
- }
130
- if (nativeView.bottomBorderLayer) {
131
- nativeView.bottomBorderLayer.removeFromSuperlayer();
132
- }
133
- if (nativeView.leftBorderLayer) {
134
- nativeView.leftBorderLayer.removeFromSuperlayer();
135
- }
340
+ nativeView.hasNonUniformBorder = false;
136
341
  }
137
- const pattern = /url\(('|")(.*?)\1\)/;
138
342
  function setUIColorFromImage(view, nativeView, callback, flip) {
139
343
  const frame = nativeView.frame;
140
344
  const boundsWidth = view.scaleX ? frame.size.width / view.scaleX : frame.size.width;
@@ -146,7 +350,7 @@ function setUIColorFromImage(view, nativeView, callback, flip) {
146
350
  const background = style.backgroundInternal;
147
351
  let imageUri = background.image;
148
352
  if (imageUri) {
149
- const match = imageUri.match(pattern);
353
+ const match = imageUri.match(uriPattern);
150
354
  if (match && match[2]) {
151
355
  imageUri = match[2];
152
356
  }
@@ -314,11 +518,11 @@ function getDrawParams(image, background, width, height) {
314
518
  }
315
519
  function uiColorFromImage(img, view, callback, flip) {
316
520
  const background = view.style.backgroundInternal;
317
- if (!img || !view.nativeViewProtected) {
521
+ const nativeView = view.nativeViewProtected;
522
+ if (!img || !nativeView) {
318
523
  callback(background.color && background.color.ios);
319
524
  return;
320
525
  }
321
- const nativeView = view.nativeViewProtected;
322
526
  const frame = nativeView.frame;
323
527
  const boundsWidth = view.scaleX ? frame.size.width / view.scaleX : frame.size.width;
324
528
  const boundsHeight = view.scaleY ? frame.size.height / view.scaleY : frame.size.height;
@@ -384,29 +588,12 @@ function cssValueToDeviceIndependentPixels(source, total) {
384
588
  return parseFloat(source);
385
589
  }
386
590
  }
387
- function drawUniformColorNonUniformBorders(nativeView, background) {
388
- const layer = nativeView.layer;
389
- layer.backgroundColor = undefined;
390
- layer.borderColor = undefined;
391
- layer.borderWidth = 0;
392
- layer.cornerRadius = 0;
393
- const { width, height } = layer.bounds.size;
394
- const { x, y } = layer.bounds.origin;
395
- const left = x;
396
- const top = y;
397
- const right = x + width;
398
- const bottom = y + height;
399
- const { min, max } = Math;
400
- const borderTopWidth = max(0, layout.toDeviceIndependentPixels(background.borderTopWidth));
401
- const borderRightWidth = max(0, layout.toDeviceIndependentPixels(background.borderRightWidth));
402
- const borderBottomWidth = max(0, layout.toDeviceIndependentPixels(background.borderBottomWidth));
403
- const borderLeftWidth = max(0, layout.toDeviceIndependentPixels(background.borderLeftWidth));
404
- const borderVWidth = borderTopWidth + borderBottomWidth;
405
- const borderHWidth = borderLeftWidth + borderRightWidth;
406
- const cappedBorderTopWidth = borderTopWidth && borderTopWidth * min(1, height / borderVWidth);
407
- const cappedBorderRightWidth = borderRightWidth && borderRightWidth * min(1, width / borderHWidth);
408
- const cappedBorderBottomWidth = borderBottomWidth && borderBottomWidth * min(1, height / borderVWidth);
409
- const cappedBorderLeftWidth = borderLeftWidth && borderLeftWidth * min(1, width / borderHWidth);
591
+ function getBorderCapRadius(a, b, c) {
592
+ return a && Math.min(a, Math.min(b, c));
593
+ }
594
+ function calculateNonUniformBorderCappedRadii(bounds, background) {
595
+ const { width, height } = bounds.size;
596
+ const { x, y } = bounds.origin;
410
597
  const outerTopLeftRadius = layout.toDeviceIndependentPixels(background.borderTopLeftRadius);
411
598
  const outerTopRightRadius = layout.toDeviceIndependentPixels(background.borderTopRightRadius);
412
599
  const outerBottomRightRadius = layout.toDeviceIndependentPixels(background.borderBottomRightRadius);
@@ -415,310 +602,420 @@ function drawUniformColorNonUniformBorders(nativeView, background) {
415
602
  const rightRadii = outerTopRightRadius + outerBottomRightRadius;
416
603
  const bottomRadii = outerBottomRightRadius + outerBottomLeftRadius;
417
604
  const leftRadii = outerBottomLeftRadius + outerTopLeftRadius;
418
- function capRadius(a, b, c) {
419
- return a && Math.min(a, Math.min(b, c));
420
- }
421
- const cappedOuterTopLeftRadius = capRadius(outerTopLeftRadius, (outerTopLeftRadius / topRadii) * width, (outerTopLeftRadius / leftRadii) * height);
422
- const cappedOuterTopRightRadius = capRadius(outerTopRightRadius, (outerTopRightRadius / topRadii) * width, (outerTopRightRadius / rightRadii) * height);
423
- const cappedOuterBottomRightRadius = capRadius(outerBottomRightRadius, (outerBottomRightRadius / bottomRadii) * width, (outerBottomRightRadius / rightRadii) * height);
424
- const cappedOuterBottomLeftRadius = capRadius(outerBottomLeftRadius, (outerBottomLeftRadius / bottomRadii) * width, (outerBottomLeftRadius / leftRadii) * height);
425
- // Outer contour
426
- const clipPath = CGPathCreateMutable();
427
- CGPathMoveToPoint(clipPath, null, left + cappedOuterTopLeftRadius, top);
428
- CGPathAddArcToPoint(clipPath, null, right, top, right, top + cappedOuterTopRightRadius, cappedOuterTopRightRadius);
429
- CGPathAddArcToPoint(clipPath, null, right, bottom, right - cappedOuterBottomRightRadius, bottom, cappedOuterBottomRightRadius);
430
- CGPathAddArcToPoint(clipPath, null, left, bottom, left, bottom - cappedOuterBottomLeftRadius, cappedOuterBottomLeftRadius);
431
- CGPathAddArcToPoint(clipPath, null, left, top, left + cappedOuterTopLeftRadius, top, cappedOuterTopLeftRadius);
432
- CGPathCloseSubpath(clipPath);
433
- nativeView.borderOriginalMask = layer.mask;
434
- const clipShapeLayer = CAShapeLayer.layer();
435
- clipShapeLayer.path = clipPath;
436
- layer.mask = clipShapeLayer;
437
- nativeView.hasBorderMask = true;
438
- if (cappedBorderLeftWidth > 0 || cappedBorderTopWidth > 0 || cappedBorderRightWidth > 0 || cappedBorderBottomWidth > 0) {
439
- const borderPath = CGPathCreateMutable();
440
- CGPathAddRect(borderPath, null, CGRectMake(left, top, width, height));
441
- // Inner contour
442
- if (cappedBorderTopWidth > 0 || cappedBorderLeftWidth > 0) {
443
- CGPathMoveToPoint(borderPath, null, left + cappedOuterTopLeftRadius, top + cappedBorderTopWidth);
444
- }
445
- else {
446
- CGPathMoveToPoint(borderPath, null, left, top);
447
- }
448
- if (cappedBorderTopWidth > 0 || cappedBorderRightWidth > 0) {
449
- const innerTopRightWRadius = max(0, cappedOuterTopRightRadius - cappedBorderRightWidth);
450
- const innerTopRightHRadius = max(0, cappedOuterTopRightRadius - cappedBorderTopWidth);
451
- const innerTopRightMaxRadius = max(innerTopRightWRadius, innerTopRightHRadius);
452
- const innerTopRightTransform = CGAffineTransformMake(innerTopRightMaxRadius && innerTopRightWRadius / innerTopRightMaxRadius, 0, 0, innerTopRightMaxRadius && innerTopRightHRadius / innerTopRightMaxRadius, right - cappedBorderRightWidth - innerTopRightWRadius, top + cappedBorderTopWidth + innerTopRightHRadius);
453
- CGPathAddArc(borderPath, innerTopRightTransform, 0, 0, innerTopRightMaxRadius, (Math.PI * 3) / 2, 0, false);
454
- }
455
- else {
456
- CGPathMoveToPoint(borderPath, null, right, top);
457
- }
458
- if (cappedBorderBottomWidth > 0 || cappedBorderRightWidth > 0) {
459
- const innerBottomRightWRadius = max(0, cappedOuterBottomRightRadius - cappedBorderRightWidth);
460
- const innerBottomRightHRadius = max(0, cappedOuterBottomRightRadius - cappedBorderBottomWidth);
461
- const innerBottomRightMaxRadius = max(innerBottomRightWRadius, innerBottomRightHRadius);
462
- const innerBottomRightTransform = CGAffineTransformMake(innerBottomRightMaxRadius && innerBottomRightWRadius / innerBottomRightMaxRadius, 0, 0, innerBottomRightMaxRadius && innerBottomRightHRadius / innerBottomRightMaxRadius, right - cappedBorderRightWidth - innerBottomRightWRadius, bottom - cappedBorderBottomWidth - innerBottomRightHRadius);
463
- CGPathAddArc(borderPath, innerBottomRightTransform, 0, 0, innerBottomRightMaxRadius, 0, Math.PI / 2, false);
464
- }
465
- else {
466
- CGPathAddLineToPoint(borderPath, null, right, bottom);
467
- }
468
- if (cappedBorderBottomWidth > 0 || cappedBorderLeftWidth > 0) {
469
- const innerBottomLeftWRadius = max(0, cappedOuterBottomLeftRadius - cappedBorderLeftWidth);
470
- const innerBottomLeftHRadius = max(0, cappedOuterBottomLeftRadius - cappedBorderBottomWidth);
471
- const innerBottomLeftMaxRadius = max(innerBottomLeftWRadius, innerBottomLeftHRadius);
472
- const innerBottomLeftTransform = CGAffineTransformMake(innerBottomLeftMaxRadius && innerBottomLeftWRadius / innerBottomLeftMaxRadius, 0, 0, innerBottomLeftMaxRadius && innerBottomLeftHRadius / innerBottomLeftMaxRadius, left + cappedBorderLeftWidth + innerBottomLeftWRadius, bottom - cappedBorderBottomWidth - innerBottomLeftHRadius);
473
- CGPathAddArc(borderPath, innerBottomLeftTransform, 0, 0, innerBottomLeftMaxRadius, Math.PI / 2, Math.PI, false);
474
- }
475
- else {
476
- CGPathAddLineToPoint(borderPath, null, left, bottom);
605
+ const cappedOuterRadii = {
606
+ topLeft: getBorderCapRadius(outerTopLeftRadius, (outerTopLeftRadius / topRadii) * width, (outerTopLeftRadius / leftRadii) * height),
607
+ topRight: getBorderCapRadius(outerTopRightRadius, (outerTopRightRadius / topRadii) * width, (outerTopRightRadius / rightRadii) * height),
608
+ bottomLeft: getBorderCapRadius(outerBottomLeftRadius, (outerBottomLeftRadius / bottomRadii) * width, (outerBottomLeftRadius / leftRadii) * height),
609
+ bottomRight: getBorderCapRadius(outerBottomRightRadius, (outerBottomRightRadius / bottomRadii) * width, (outerBottomRightRadius / rightRadii) * height),
610
+ };
611
+ return cappedOuterRadii;
612
+ }
613
+ function drawNonUniformBorders(nativeView, background) {
614
+ const layer = nativeView.layer;
615
+ const layerBounds = layer.bounds;
616
+ layer.borderColor = null;
617
+ layer.borderWidth = 0;
618
+ layer.cornerRadius = 0;
619
+ const cappedOuterRadii = calculateNonUniformBorderCappedRadii(layerBounds, background);
620
+ if (nativeView.maskType === iosViewUtils.LayerMask.BORDER && layer.mask instanceof CAShapeLayer) {
621
+ layer.mask.path = generateNonUniformBorderOuterClipPath(layerBounds, cappedOuterRadii);
622
+ }
623
+ if (background.hasBorderWidth()) {
624
+ if (!nativeView.hasNonUniformBorder) {
625
+ nativeView.borderLayer = CAShapeLayer.new();
626
+ nativeView.borderLayer.fillRule = kCAFillRuleEvenOdd;
627
+ layer.addSublayer(nativeView.borderLayer);
628
+ nativeView.hasNonUniformBorder = true;
477
629
  }
478
- if (cappedBorderTopWidth > 0 || cappedBorderLeftWidth > 0) {
479
- const innerTopLeftWRadius = max(0, cappedOuterTopLeftRadius - cappedBorderLeftWidth);
480
- const innerTopLeftHRadius = max(0, cappedOuterTopLeftRadius - cappedBorderTopWidth);
481
- const innerTopLeftMaxRadius = max(innerTopLeftWRadius, innerTopLeftHRadius);
482
- const innerTopLeftTransform = CGAffineTransformMake(innerTopLeftMaxRadius && innerTopLeftWRadius / innerTopLeftMaxRadius, 0, 0, innerTopLeftMaxRadius && innerTopLeftHRadius / innerTopLeftMaxRadius, left + cappedBorderLeftWidth + innerTopLeftWRadius, top + cappedBorderTopWidth + innerTopLeftHRadius);
483
- CGPathAddArc(borderPath, innerTopLeftTransform, 0, 0, innerTopLeftMaxRadius, Math.PI, (Math.PI * 3) / 2, false);
630
+ if (background.hasUniformBorderColor()) {
631
+ nativeView.borderLayer.fillColor = background.borderTopColor?.ios?.CGColor || UIColor.blackColor.CGColor;
632
+ nativeView.borderLayer.path = generateNonUniformBorderInnerClipPath(layerBounds, background, cappedOuterRadii);
484
633
  }
485
634
  else {
486
- CGPathAddLineToPoint(borderPath, null, left, top);
635
+ // Non-uniform borders need more layers in order to display multiple colors at the same time
636
+ let borderTopLayer, borderRightLayer, borderBottomLayer, borderLeftLayer;
637
+ if (!nativeView.hasNonUniformBorderColor) {
638
+ const maskLayer = CAShapeLayer.new();
639
+ maskLayer.fillRule = kCAFillRuleEvenOdd;
640
+ nativeView.borderLayer.mask = maskLayer;
641
+ borderTopLayer = CAShapeLayer.new();
642
+ borderRightLayer = CAShapeLayer.new();
643
+ borderBottomLayer = CAShapeLayer.new();
644
+ borderLeftLayer = CAShapeLayer.new();
645
+ nativeView.borderLayer.addSublayer(borderTopLayer);
646
+ nativeView.borderLayer.addSublayer(borderRightLayer);
647
+ nativeView.borderLayer.addSublayer(borderBottomLayer);
648
+ nativeView.borderLayer.addSublayer(borderLeftLayer);
649
+ nativeView.hasNonUniformBorderColor = true;
650
+ }
651
+ else {
652
+ borderTopLayer = nativeView.borderLayer.sublayers[0];
653
+ borderRightLayer = nativeView.borderLayer.sublayers[1];
654
+ borderBottomLayer = nativeView.borderLayer.sublayers[2];
655
+ borderLeftLayer = nativeView.borderLayer.sublayers[3];
656
+ }
657
+ const paths = generateNonUniformMultiColorBorderPaths(layerBounds, background);
658
+ borderTopLayer.fillColor = background.borderTopColor?.ios?.CGColor || UIColor.blackColor.CGColor;
659
+ borderTopLayer.path = paths[0];
660
+ borderRightLayer.fillColor = background.borderRightColor?.ios?.CGColor || UIColor.blackColor.CGColor;
661
+ borderRightLayer.path = paths[1];
662
+ borderBottomLayer.fillColor = background.borderBottomColor?.ios?.CGColor || UIColor.blackColor.CGColor;
663
+ borderBottomLayer.path = paths[2];
664
+ borderLeftLayer.fillColor = background.borderLeftColor?.ios?.CGColor || UIColor.blackColor.CGColor;
665
+ borderLeftLayer.path = paths[3];
666
+ // Clip inner area to create borders
667
+ if (nativeView.borderLayer.mask instanceof CAShapeLayer) {
668
+ nativeView.borderLayer.mask.path = generateNonUniformBorderInnerClipPath(layerBounds, background, cappedOuterRadii);
669
+ }
487
670
  }
488
- CGPathCloseSubpath(borderPath);
489
- const borderLayer = CAShapeLayer.layer();
490
- borderLayer.fillColor = (background.borderTopColor && background.borderTopColor.ios.CGColor) || UIColor.blackColor.CGColor;
491
- borderLayer.fillRule = kCAFillRuleEvenOdd;
492
- borderLayer.path = borderPath;
493
- layer.addSublayer(borderLayer);
494
- nativeView.borderLayer = borderLayer;
495
671
  }
496
- nativeView.hasNonUniformBorder = true;
497
672
  }
498
- function drawNoRadiusNonUniformBorders(nativeView, background) {
499
- const borderLayer = CALayer.layer();
500
- nativeView.layer.addSublayer(borderLayer);
501
- nativeView.borderLayer = borderLayer;
502
- borderLayer.borderColor = undefined;
503
- borderLayer.borderWidth = 0;
504
- borderLayer.cornerRadius = 0;
505
- const layerBounds = nativeView.layer.bounds;
506
- const layerOrigin = layerBounds.origin;
507
- const layerSize = layerBounds.size;
508
- const nativeViewLayerBounds = {
509
- left: layerOrigin.x,
510
- top: layerOrigin.y,
511
- bottom: layerSize.height,
512
- right: layerSize.width,
673
+ function calculateInnerBorderClipRadius(radius, insetX, insetY) {
674
+ const innerXRadius = Math.max(0, radius - insetX);
675
+ const innerYRadius = Math.max(0, radius - insetY);
676
+ const innerMaxRadius = Math.max(innerXRadius, innerYRadius);
677
+ return {
678
+ xRadius: innerXRadius,
679
+ yRadius: innerYRadius,
680
+ maxRadius: innerMaxRadius,
681
+ };
682
+ }
683
+ /**
684
+ * Generates a path that represents the rounded view area.
685
+ *
686
+ * @param bounds
687
+ * @param cappedRadii
688
+ * @param offset
689
+ * @returns
690
+ */
691
+ export function generateNonUniformBorderOuterClipPath(bounds, cappedRadii, offset = 0) {
692
+ const { width, height } = bounds.size;
693
+ const { x, y } = bounds.origin;
694
+ const left = x - offset;
695
+ const top = y - offset;
696
+ const right = x + width + offset;
697
+ const bottom = y + height + offset;
698
+ const clipPath = CGPathCreateMutable();
699
+ CGPathMoveToPoint(clipPath, null, left + cappedRadii.topLeft, top);
700
+ CGPathAddArcToPoint(clipPath, null, right, top, right, top + cappedRadii.topRight, cappedRadii.topRight);
701
+ CGPathAddArcToPoint(clipPath, null, right, bottom, right - cappedRadii.bottomRight, bottom, cappedRadii.bottomRight);
702
+ CGPathAddArcToPoint(clipPath, null, left, bottom, left, bottom - cappedRadii.bottomLeft, cappedRadii.bottomLeft);
703
+ CGPathAddArcToPoint(clipPath, null, left, top, left + cappedRadii.topLeft, top, cappedRadii.topLeft);
704
+ CGPathCloseSubpath(clipPath);
705
+ return clipPath;
706
+ }
707
+ /**
708
+ * Generates a path that represents the area inside borders.
709
+ *
710
+ * @param bounds
711
+ * @param background
712
+ * @param cappedOuterRadii
713
+ * @returns
714
+ */
715
+ function generateNonUniformBorderInnerClipPath(bounds, background, cappedOuterRadii) {
716
+ const { width, height } = bounds.size;
717
+ const { x, y } = bounds.origin;
718
+ const position = {
719
+ left: x,
720
+ top: y,
721
+ bottom: y + height,
722
+ right: x + width,
513
723
  };
514
- const top = layout.toDeviceIndependentPixels(background.borderTopWidth);
515
- const right = layout.toDeviceIndependentPixels(background.borderRightWidth);
516
- const bottom = layout.toDeviceIndependentPixels(background.borderBottomWidth);
517
- const left = layout.toDeviceIndependentPixels(background.borderLeftWidth);
724
+ const borderTopWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderTopWidth));
725
+ const borderRightWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderRightWidth));
726
+ const borderBottomWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderBottomWidth));
727
+ const borderLeftWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderLeftWidth));
728
+ const borderVWidth = borderTopWidth + borderBottomWidth;
729
+ const borderHWidth = borderLeftWidth + borderRightWidth;
730
+ const cappedBorderTopWidth = borderTopWidth && borderTopWidth * Math.min(1, height / borderVWidth);
731
+ const cappedBorderRightWidth = borderRightWidth && borderRightWidth * Math.min(1, width / borderHWidth);
732
+ const cappedBorderBottomWidth = borderBottomWidth && borderBottomWidth * Math.min(1, height / borderVWidth);
733
+ const cappedBorderLeftWidth = borderLeftWidth && borderLeftWidth * Math.min(1, width / borderHWidth);
734
+ const clipPath = CGPathCreateMutable();
735
+ CGPathAddRect(clipPath, null, CGRectMake(x, y, width, height));
736
+ // Inner clip paths
737
+ if (cappedBorderTopWidth > 0 || cappedBorderLeftWidth > 0) {
738
+ CGPathMoveToPoint(clipPath, null, position.left + cappedOuterRadii.topLeft, position.top + cappedBorderTopWidth);
739
+ }
740
+ else {
741
+ CGPathMoveToPoint(clipPath, null, position.left, position.top);
742
+ }
743
+ if (cappedBorderTopWidth > 0 || cappedBorderRightWidth > 0) {
744
+ const { xRadius, yRadius, maxRadius } = calculateInnerBorderClipRadius(cappedOuterRadii.topRight, cappedBorderRightWidth, cappedBorderTopWidth);
745
+ const innerTopRightTransform = CGAffineTransformMake(maxRadius && xRadius / maxRadius, 0, 0, maxRadius && yRadius / maxRadius, position.right - cappedBorderRightWidth - xRadius, position.top + cappedBorderTopWidth + yRadius);
746
+ CGPathAddArc(clipPath, innerTopRightTransform, 0, 0, maxRadius, (Math.PI * 3) / 2, 0, false);
747
+ }
748
+ else {
749
+ CGPathAddLineToPoint(clipPath, null, position.right, position.top);
750
+ }
751
+ if (cappedBorderBottomWidth > 0 || cappedBorderRightWidth > 0) {
752
+ const { xRadius, yRadius, maxRadius } = calculateInnerBorderClipRadius(cappedOuterRadii.bottomRight, cappedBorderRightWidth, cappedBorderBottomWidth);
753
+ const innerBottomRightTransform = CGAffineTransformMake(maxRadius && xRadius / maxRadius, 0, 0, maxRadius && yRadius / maxRadius, position.right - cappedBorderRightWidth - xRadius, position.bottom - cappedBorderBottomWidth - yRadius);
754
+ CGPathAddArc(clipPath, innerBottomRightTransform, 0, 0, maxRadius, 0, Math.PI / 2, false);
755
+ }
756
+ else {
757
+ CGPathAddLineToPoint(clipPath, null, position.right, position.bottom);
758
+ }
759
+ if (cappedBorderBottomWidth > 0 || cappedBorderLeftWidth > 0) {
760
+ const { xRadius, yRadius, maxRadius } = calculateInnerBorderClipRadius(cappedOuterRadii.bottomLeft, cappedBorderLeftWidth, cappedBorderBottomWidth);
761
+ const innerBottomLeftTransform = CGAffineTransformMake(maxRadius && xRadius / maxRadius, 0, 0, maxRadius && yRadius / maxRadius, position.left + cappedBorderLeftWidth + xRadius, position.bottom - cappedBorderBottomWidth - yRadius);
762
+ CGPathAddArc(clipPath, innerBottomLeftTransform, 0, 0, maxRadius, Math.PI / 2, Math.PI, false);
763
+ }
764
+ else {
765
+ CGPathAddLineToPoint(clipPath, null, position.left, position.bottom);
766
+ }
767
+ if (cappedBorderTopWidth > 0 || cappedBorderLeftWidth > 0) {
768
+ const { xRadius, yRadius, maxRadius } = calculateInnerBorderClipRadius(cappedOuterRadii.topLeft, cappedBorderLeftWidth, cappedBorderTopWidth);
769
+ const innerTopLeftTransform = CGAffineTransformMake(maxRadius && xRadius / maxRadius, 0, 0, maxRadius && yRadius / maxRadius, position.left + cappedBorderLeftWidth + xRadius, position.top + cappedBorderTopWidth + yRadius);
770
+ CGPathAddArc(clipPath, innerTopLeftTransform, 0, 0, maxRadius, Math.PI, (Math.PI * 3) / 2, false);
771
+ }
772
+ else {
773
+ CGPathAddLineToPoint(clipPath, null, position.left, position.top);
774
+ }
775
+ CGPathCloseSubpath(clipPath);
776
+ return clipPath;
777
+ }
778
+ /**
779
+ * Calculates the needed widths for creating triangular shapes for each border.
780
+ * To achieve this, all border widths are scaled according to view bounds.
781
+ *
782
+ * @param bounds
783
+ * @param background
784
+ * @returns
785
+ */
786
+ function getBorderTriangleWidths(bounds, background) {
787
+ const width = bounds.origin.x + bounds.size.width;
788
+ const height = bounds.origin.y + bounds.size.height;
789
+ const borderTopWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderTopWidth));
790
+ const borderRightWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderRightWidth));
791
+ const borderBottomWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderBottomWidth));
792
+ const borderLeftWidth = Math.max(0, layout.toDeviceIndependentPixels(background.borderLeftWidth));
793
+ const verticalBorderWidth = borderTopWidth + borderBottomWidth;
794
+ const horizontalBorderWidth = borderLeftWidth + borderRightWidth;
795
+ let verticalBorderMultiplier = verticalBorderWidth > 0 ? height / verticalBorderWidth : 0;
796
+ let horizontalBorderMultiplier = horizontalBorderWidth > 0 ? width / horizontalBorderWidth : 0;
797
+ // Both directions should consider each other in order to scale widths properly, as a view might have different width and height
798
+ if (verticalBorderMultiplier > 0 && verticalBorderMultiplier < horizontalBorderMultiplier) {
799
+ horizontalBorderMultiplier -= horizontalBorderMultiplier - verticalBorderMultiplier;
800
+ }
801
+ if (horizontalBorderMultiplier > 0 && horizontalBorderMultiplier < verticalBorderMultiplier) {
802
+ verticalBorderMultiplier -= verticalBorderMultiplier - horizontalBorderMultiplier;
803
+ }
804
+ return {
805
+ top: borderTopWidth * verticalBorderMultiplier,
806
+ right: borderRightWidth * horizontalBorderMultiplier,
807
+ bottom: borderBottomWidth * verticalBorderMultiplier,
808
+ left: borderLeftWidth * horizontalBorderMultiplier,
809
+ };
810
+ }
811
+ /**
812
+ * Generates paths for visualizing borders with different colors per side.
813
+ * This is achieved by extending all borders enough to consume entire view size,
814
+ * then using an even-odd inner mask to clip and eventually render borders according to their corresponding width.
815
+ *
816
+ * @param bounds
817
+ * @param background
818
+ * @returns
819
+ */
820
+ function generateNonUniformMultiColorBorderPaths(bounds, background) {
821
+ const { width, height } = bounds.size;
822
+ const { x, y } = bounds.origin;
823
+ const position = {
824
+ left: x,
825
+ top: y,
826
+ bottom: y + height,
827
+ right: x + width,
828
+ };
829
+ const borderWidths = getBorderTriangleWidths(bounds, background);
830
+ const paths = new Array(4);
518
831
  const lto = {
519
- x: nativeViewLayerBounds.left,
520
- y: nativeViewLayerBounds.top,
832
+ x: position.left,
833
+ y: position.top,
521
834
  }; // left-top-outside
522
835
  const lti = {
523
- x: nativeViewLayerBounds.left + left,
524
- y: nativeViewLayerBounds.top + top,
836
+ x: position.left + borderWidths.left,
837
+ y: position.top + borderWidths.top,
525
838
  }; // left-top-inside
526
839
  const rto = {
527
- x: nativeViewLayerBounds.right,
528
- y: nativeViewLayerBounds.top,
840
+ x: position.right,
841
+ y: position.top,
529
842
  }; // right-top-outside
530
843
  const rti = {
531
- x: nativeViewLayerBounds.right - right,
532
- y: nativeViewLayerBounds.top + top,
844
+ x: position.right - borderWidths.right,
845
+ y: position.top + borderWidths.top,
533
846
  }; // right-top-inside
534
847
  const rbo = {
535
- x: nativeViewLayerBounds.right,
536
- y: nativeViewLayerBounds.bottom,
848
+ x: position.right,
849
+ y: position.bottom,
537
850
  }; // right-bottom-outside
538
851
  const rbi = {
539
- x: nativeViewLayerBounds.right - right,
540
- y: nativeViewLayerBounds.bottom - bottom,
852
+ x: position.right - borderWidths.right,
853
+ y: position.bottom - borderWidths.bottom,
541
854
  }; // right-bottom-inside
542
855
  const lbo = {
543
- x: nativeViewLayerBounds.left,
544
- y: nativeViewLayerBounds.bottom,
856
+ x: position.left,
857
+ y: position.bottom,
545
858
  }; // left-bottom-outside
546
859
  const lbi = {
547
- x: nativeViewLayerBounds.left + left,
548
- y: nativeViewLayerBounds.bottom - bottom,
860
+ x: position.left + borderWidths.left,
861
+ y: position.bottom - borderWidths.bottom,
549
862
  }; // left-bottom-inside
550
- let hasNonUniformBorder;
551
863
  const borderTopColor = background.borderTopColor;
552
- if (top > 0 && borderTopColor && borderTopColor.ios) {
864
+ const borderRightColor = background.borderRightColor;
865
+ const borderBottomColor = background.borderBottomColor;
866
+ const borderLeftColor = background.borderLeftColor;
867
+ if (borderWidths.top > 0 && borderTopColor?.ios) {
553
868
  const topBorderPath = CGPathCreateMutable();
554
869
  CGPathMoveToPoint(topBorderPath, null, lto.x, lto.y);
555
870
  CGPathAddLineToPoint(topBorderPath, null, rto.x, rto.y);
556
871
  CGPathAddLineToPoint(topBorderPath, null, rti.x, rti.y);
557
- CGPathAddLineToPoint(topBorderPath, null, lti.x, lti.y);
872
+ if (rti.x !== lti.x) {
873
+ CGPathAddLineToPoint(topBorderPath, null, lti.x, lti.y);
874
+ }
558
875
  CGPathAddLineToPoint(topBorderPath, null, lto.x, lto.y);
559
- const topBorderLayer = CAShapeLayer.layer();
560
- topBorderLayer.fillColor = background.borderTopColor.ios.CGColor;
561
- topBorderLayer.path = topBorderPath;
562
- borderLayer.addSublayer(topBorderLayer);
563
- nativeView.topBorderLayer = topBorderLayer;
564
- hasNonUniformBorder = true;
876
+ paths[0] = topBorderPath;
565
877
  }
566
- const borderRightColor = background.borderRightColor;
567
- if (right > 0 && borderRightColor && borderRightColor.ios) {
878
+ if (borderWidths.right > 0 && borderRightColor?.ios) {
568
879
  const rightBorderPath = CGPathCreateMutable();
569
880
  CGPathMoveToPoint(rightBorderPath, null, rto.x, rto.y);
570
881
  CGPathAddLineToPoint(rightBorderPath, null, rbo.x, rbo.y);
571
882
  CGPathAddLineToPoint(rightBorderPath, null, rbi.x, rbi.y);
572
- CGPathAddLineToPoint(rightBorderPath, null, rti.x, rti.y);
883
+ if (rbi.y !== rti.y) {
884
+ CGPathAddLineToPoint(rightBorderPath, null, rti.x, rti.y);
885
+ }
573
886
  CGPathAddLineToPoint(rightBorderPath, null, rto.x, rto.y);
574
- const rightBorderLayer = CAShapeLayer.layer();
575
- rightBorderLayer.fillColor = background.borderRightColor.ios.CGColor;
576
- rightBorderLayer.path = rightBorderPath;
577
- borderLayer.addSublayer(rightBorderLayer);
578
- nativeView.rightBorderLayer = rightBorderLayer;
579
- hasNonUniformBorder = true;
887
+ paths[1] = rightBorderPath;
580
888
  }
581
- const borderBottomColor = background.borderBottomColor;
582
- if (bottom > 0 && borderBottomColor && borderBottomColor.ios) {
889
+ if (borderWidths.bottom > 0 && borderBottomColor?.ios) {
583
890
  const bottomBorderPath = CGPathCreateMutable();
584
891
  CGPathMoveToPoint(bottomBorderPath, null, rbo.x, rbo.y);
585
892
  CGPathAddLineToPoint(bottomBorderPath, null, lbo.x, lbo.y);
586
893
  CGPathAddLineToPoint(bottomBorderPath, null, lbi.x, lbi.y);
587
- CGPathAddLineToPoint(bottomBorderPath, null, rbi.x, rbi.y);
894
+ if (lbi.x !== rbi.x) {
895
+ CGPathAddLineToPoint(bottomBorderPath, null, rbi.x, rbi.y);
896
+ }
588
897
  CGPathAddLineToPoint(bottomBorderPath, null, rbo.x, rbo.y);
589
- const bottomBorderLayer = CAShapeLayer.layer();
590
- bottomBorderLayer.fillColor = background.borderBottomColor.ios.CGColor;
591
- bottomBorderLayer.path = bottomBorderPath;
592
- borderLayer.addSublayer(bottomBorderLayer);
593
- nativeView.bottomBorderLayer = bottomBorderLayer;
594
- hasNonUniformBorder = true;
898
+ paths[2] = bottomBorderPath;
595
899
  }
596
- const borderLeftColor = background.borderLeftColor;
597
- if (left > 0 && borderLeftColor && borderLeftColor.ios) {
900
+ if (borderWidths.left > 0 && borderLeftColor?.ios) {
598
901
  const leftBorderPath = CGPathCreateMutable();
599
902
  CGPathMoveToPoint(leftBorderPath, null, lbo.x, lbo.y);
600
903
  CGPathAddLineToPoint(leftBorderPath, null, lto.x, lto.y);
601
904
  CGPathAddLineToPoint(leftBorderPath, null, lti.x, lti.y);
602
- CGPathAddLineToPoint(leftBorderPath, null, lbi.x, lbi.y);
905
+ if (lti.y !== lbi.y) {
906
+ CGPathAddLineToPoint(leftBorderPath, null, lbi.x, lbi.y);
907
+ }
603
908
  CGPathAddLineToPoint(leftBorderPath, null, lbo.x, lbo.y);
604
- const leftBorderLayer = CAShapeLayer.layer();
605
- leftBorderLayer.fillColor = background.borderLeftColor.ios.CGColor;
606
- leftBorderLayer.path = leftBorderPath;
607
- borderLayer.addSublayer(leftBorderLayer);
608
- nativeView.leftBorderLayer = leftBorderLayer;
609
- hasNonUniformBorder = true;
610
- }
611
- nativeView.hasNonUniformBorder = hasNonUniformBorder;
909
+ paths[3] = leftBorderPath;
910
+ }
911
+ return paths;
612
912
  }
613
- // TODO: use sublayer if its applied to a layout
614
- function drawBoxShadow(nativeView, view, boxShadow, background, useSubLayer = false) {
615
- const layer = iOSNativeHelper.getShadowLayer(nativeView, 'ns-box-shadow');
616
- layer.masksToBounds = false;
617
- nativeView.clipsToBounds = false;
618
- // this is required (if not, shadow will get cutoff at parent's dimensions)
619
- // nativeView.clipsToBounds doesn't work
620
- view.setProperty('clipToBounds', false);
621
- if (!background.color?.a) {
622
- // add white background if view has a transparent background
623
- layer.backgroundColor = UIColor.whiteColor.CGColor;
624
- }
625
- // shadow opacity is handled on the shadow's color instance
626
- layer.shadowOpacity = boxShadow.color?.a ? boxShadow.color?.a / 255 : 1;
627
- layer.shadowRadius = Length.toDevicePixels(boxShadow.blurRadius, 0.0);
628
- layer.shadowColor = boxShadow.color.ios.CGColor;
629
- // prettier-ignore
630
- layer.shadowOffset = CGSizeMake(Length.toDevicePixels(boxShadow.offsetX, 0.0), Length.toDevicePixels(boxShadow.offsetY, 0.0));
631
- // this should match the view's border radius
632
- let cornerRadius;
633
- if (typeof view.style.borderRadius !== 'number') {
634
- cornerRadius = Length.toDevicePixels(view.style.borderRadius, 0.0);
913
+ function drawBoxShadow(view) {
914
+ const background = view.style.backgroundInternal;
915
+ const nativeView = view.nativeViewProtected;
916
+ const layer = nativeView.layer;
917
+ // There is no parent to add shadow to
918
+ if (!layer.superlayer) {
919
+ return;
920
+ }
921
+ const bounds = nativeView.bounds;
922
+ const boxShadow = background.getBoxShadow();
923
+ // Initialize outer shadows
924
+ let outerShadowContainerLayer;
925
+ if (nativeView.outerShadowContainerLayer) {
926
+ outerShadowContainerLayer = nativeView.outerShadowContainerLayer;
635
927
  }
636
928
  else {
637
- cornerRadius = view.style.borderRadius;
929
+ outerShadowContainerLayer = CALayer.new();
930
+ // TODO: Make this dynamic when views get support for multiple shadows
931
+ const shadowLayer = CALayer.new();
932
+ // This mask is necessary to maintain transparent background
933
+ const maskLayer = CAShapeLayer.new();
934
+ maskLayer.fillRule = kCAFillRuleEvenOdd;
935
+ shadowLayer.mask = maskLayer;
936
+ outerShadowContainerLayer.addSublayer(shadowLayer);
937
+ // Instead of nesting it, add shadow container layer underneath view so that it's not affected by border masking
938
+ layer.superlayer.insertSublayerBelow(outerShadowContainerLayer, layer);
939
+ nativeView.outerShadowContainerLayer = outerShadowContainerLayer;
940
+ }
941
+ // Apply clip path to shadow
942
+ if (nativeView.maskType === iosViewUtils.LayerMask.CLIP_PATH && layer.mask instanceof CAShapeLayer) {
943
+ if (!outerShadowContainerLayer.mask) {
944
+ outerShadowContainerLayer.mask = CAShapeLayer.new();
945
+ }
946
+ if (outerShadowContainerLayer.mask instanceof CAShapeLayer) {
947
+ outerShadowContainerLayer.mask.path = layer.mask.path;
948
+ }
949
+ }
950
+ outerShadowContainerLayer.bounds = bounds;
951
+ outerShadowContainerLayer.anchorPoint = layer.anchorPoint;
952
+ outerShadowContainerLayer.position = nativeView.center;
953
+ outerShadowContainerLayer.zPosition = layer.zPosition;
954
+ // Inherit view visibility values
955
+ outerShadowContainerLayer.opacity = layer.opacity;
956
+ outerShadowContainerLayer.hidden = layer.hidden;
957
+ const outerShadowLayers = outerShadowContainerLayer.sublayers;
958
+ if (outerShadowLayers?.count) {
959
+ for (let i = 0, count = outerShadowLayers.count; i < count; i++) {
960
+ const shadowLayer = outerShadowLayers[i];
961
+ const shadowRadius = layout.toDeviceIndependentPixels(boxShadow.blurRadius);
962
+ const spreadRadius = layout.toDeviceIndependentPixels(boxShadow.spreadRadius);
963
+ const offsetX = layout.toDeviceIndependentPixels(boxShadow.offsetX);
964
+ const offsetY = layout.toDeviceIndependentPixels(boxShadow.offsetY);
965
+ const { maskPath, shadowPath } = ios.generateShadowLayerPaths(view, bounds);
966
+ shadowLayer.allowsEdgeAntialiasing = true;
967
+ shadowLayer.contentsScale = Screen.mainScreen.scale;
968
+ // Shadow opacity is handled on the shadow's color instance
969
+ shadowLayer.shadowOpacity = boxShadow.color?.a ? boxShadow.color.a / 255 : 1;
970
+ shadowLayer.shadowRadius = shadowRadius;
971
+ shadowLayer.shadowColor = boxShadow.color?.ios?.CGColor;
972
+ shadowLayer.shadowOffset = CGSizeMake(offsetX, offsetY);
973
+ // Apply spread radius by expanding shadow layer bounds (this has a nice glow with radii set to 0)
974
+ shadowLayer.shadowPath = shadowPath;
975
+ // A mask that ensures that view maintains transparent background
976
+ if (shadowLayer.mask instanceof CAShapeLayer) {
977
+ shadowLayer.mask.path = maskPath;
978
+ }
979
+ }
638
980
  }
639
- // apply spreadRadius by expanding shadow layer bounds
640
- // prettier-ignore
641
- const bounds = CGRectInset(nativeView.bounds, -Length.toDevicePixels(boxShadow.spreadRadius, 0.0), -Length.toDevicePixels(boxShadow.spreadRadius, 0.0));
642
- // This has the nice glow with box shadow of 0,0
643
- layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(bounds, cornerRadius).CGPath;
644
981
  }
645
982
  function clearBoxShadow(nativeView) {
646
- nativeView.clipsToBounds = true;
647
- const layer = iOSNativeHelper.getShadowLayer(nativeView, 'ns-box-shadow', false);
648
- if (!layer) {
649
- return;
983
+ if (nativeView.outerShadowContainerLayer) {
984
+ nativeView.outerShadowContainerLayer.removeFromSuperlayer();
985
+ nativeView.outerShadowContainerLayer = null;
650
986
  }
651
- layer.masksToBounds = true;
652
- layer.shadowOffset = CGSizeMake(0, 0);
653
- layer.shadowColor = UIColor.clearColor.CGColor;
654
- layer.cornerRadius = 0.0;
655
- layer.shadowRadius = 0.0;
656
- layer.shadowOpacity = 0.0;
657
987
  }
658
- function drawClipPath(nativeView, background) {
659
- const layer = nativeView.layer;
660
- const layerBounds = layer.bounds;
661
- const layerOrigin = layerBounds.origin;
662
- const layerSize = layerBounds.size;
663
- const bounds = {
664
- left: layerOrigin.x,
665
- top: layerOrigin.y,
666
- bottom: layerSize.height,
667
- right: layerSize.width,
668
- };
669
- if (bounds.right === 0 || bounds.bottom === 0) {
670
- return;
671
- }
672
- let path;
673
- const clipPath = background.clipPath;
674
- const functionName = clipPath.substring(0, clipPath.indexOf('('));
675
- const value = clipPath.replace(`${functionName}(`, '').replace(')', '');
676
- switch (functionName) {
677
- case 'rect':
678
- path = rectPath(value, bounds);
679
- break;
680
- case 'inset':
681
- path = insetPath(value, bounds);
682
- break;
683
- case 'circle':
684
- path = circlePath(value, bounds);
685
- break;
686
- case 'ellipse':
687
- path = ellipsePath(value, bounds);
688
- break;
689
- case 'polygon':
690
- path = polygonPath(value, bounds);
691
- break;
692
- }
693
- if (path) {
694
- const shape = CAShapeLayer.layer();
695
- shape.path = path;
696
- layer.mask = shape;
697
- nativeView.clipsToBounds = true;
698
- const borderWidth = background.getUniformBorderWidth();
699
- const borderColor = background.getUniformBorderColor();
700
- if (borderWidth > 0 && borderColor instanceof Color) {
701
- const borderLayer = CAShapeLayer.layer();
702
- borderLayer.path = path;
703
- borderLayer.lineWidth = borderWidth * 2;
704
- borderLayer.strokeColor = borderColor.ios.CGColor;
705
- borderLayer.fillColor = clearCGColor;
706
- borderLayer.frame = nativeView.bounds;
707
- layer.borderColor = undefined;
708
- layer.borderWidth = 0;
709
- layer.addSublayer(borderLayer);
710
- }
711
- }
988
+ /**
989
+ * Creates a mask that ensures no shadow will be displayed underneath transparent backgrounds.
990
+ *
991
+ * @param bounds
992
+ * @param boxShadow
993
+ * @param bordersClipPath
994
+ * @returns
995
+ */
996
+ function generateShadowMaskPath(bounds, boxShadow, innerClipPath) {
997
+ const shadowRadius = layout.toDeviceIndependentPixels(boxShadow.blurRadius);
998
+ const spreadRadius = layout.toDeviceIndependentPixels(boxShadow.spreadRadius);
999
+ const offsetX = layout.toDeviceIndependentPixels(boxShadow.offsetX);
1000
+ const offsetY = layout.toDeviceIndependentPixels(boxShadow.offsetY);
1001
+ // This value has to be large enough to avoid clipping shadow halo effect
1002
+ const outerRectRadius = shadowRadius * 3 + spreadRadius;
1003
+ const maskPath = CGPathCreateMutable();
1004
+ // Proper clip position and size
1005
+ const outerRect = CGRectOffset(CGRectInset(bounds, -outerRectRadius, -outerRectRadius), offsetX, offsetY);
1006
+ CGPathAddPath(maskPath, null, innerClipPath);
1007
+ CGPathAddRect(maskPath, null, outerRect);
1008
+ return maskPath;
712
1009
  }
713
- function rectPath(value, bounds) {
1010
+ function rectPath(value, position) {
714
1011
  const arr = value.split(/[\s]+/);
715
- const top = cssValueToDeviceIndependentPixels(arr[0], bounds.top);
716
- const right = cssValueToDeviceIndependentPixels(arr[1], bounds.right);
717
- const bottom = cssValueToDeviceIndependentPixels(arr[2], bounds.bottom);
718
- const left = cssValueToDeviceIndependentPixels(arr[3], bounds.left);
1012
+ const top = cssValueToDeviceIndependentPixels(arr[0], position.top);
1013
+ const right = cssValueToDeviceIndependentPixels(arr[1], position.right);
1014
+ const bottom = cssValueToDeviceIndependentPixels(arr[2], position.bottom);
1015
+ const left = cssValueToDeviceIndependentPixels(arr[3], position.left);
719
1016
  return UIBezierPath.bezierPathWithRect(CGRectMake(left, top, right - left, bottom - top)).CGPath;
720
1017
  }
721
- function insetPath(value, bounds) {
1018
+ function insetPath(value, position) {
722
1019
  const arr = value.split(/[\s]+/);
723
1020
  let topString;
724
1021
  let rightString;
@@ -742,40 +1039,40 @@ function insetPath(value, bounds) {
742
1039
  bottomString = arr[2];
743
1040
  leftString = arr[3];
744
1041
  }
745
- const top = cssValueToDeviceIndependentPixels(topString, bounds.bottom);
746
- const right = cssValueToDeviceIndependentPixels('100%', bounds.right) - cssValueToDeviceIndependentPixels(rightString, bounds.right);
747
- const bottom = cssValueToDeviceIndependentPixels('100%', bounds.bottom) - cssValueToDeviceIndependentPixels(bottomString, bounds.bottom);
748
- const left = cssValueToDeviceIndependentPixels(leftString, bounds.right);
1042
+ const top = cssValueToDeviceIndependentPixels(topString, position.bottom);
1043
+ const right = cssValueToDeviceIndependentPixels('100%', position.right) - cssValueToDeviceIndependentPixels(rightString, position.right);
1044
+ const bottom = cssValueToDeviceIndependentPixels('100%', position.bottom) - cssValueToDeviceIndependentPixels(bottomString, position.bottom);
1045
+ const left = cssValueToDeviceIndependentPixels(leftString, position.right);
749
1046
  return UIBezierPath.bezierPathWithRect(CGRectMake(left, top, right - left, bottom - top)).CGPath;
750
1047
  }
751
- function circlePath(value, bounds) {
1048
+ function circlePath(value, position) {
752
1049
  const arr = value.split(/[\s]+/);
753
- const radius = cssValueToDeviceIndependentPixels(arr[0], (bounds.right > bounds.bottom ? bounds.bottom : bounds.right) / 2);
754
- const y = cssValueToDeviceIndependentPixels(arr[2], bounds.bottom);
755
- const x = cssValueToDeviceIndependentPixels(arr[3], bounds.right);
1050
+ const radius = cssValueToDeviceIndependentPixels(arr[0], (position.right > position.bottom ? position.bottom : position.right) / 2);
1051
+ const y = cssValueToDeviceIndependentPixels(arr[2], position.bottom);
1052
+ const x = cssValueToDeviceIndependentPixels(arr[3], position.right);
756
1053
  return UIBezierPath.bezierPathWithArcCenterRadiusStartAngleEndAngleClockwise(CGPointMake(x, y), radius, 0, 360, true).CGPath;
757
1054
  }
758
- function ellipsePath(value, bounds) {
1055
+ function ellipsePath(value, position) {
759
1056
  const arr = value.split(/[\s]+/);
760
- const rX = cssValueToDeviceIndependentPixels(arr[0], bounds.right);
761
- const rY = cssValueToDeviceIndependentPixels(arr[1], bounds.bottom);
762
- const cX = cssValueToDeviceIndependentPixels(arr[3], bounds.right);
763
- const cY = cssValueToDeviceIndependentPixels(arr[4], bounds.bottom);
1057
+ const rX = cssValueToDeviceIndependentPixels(arr[0], position.right);
1058
+ const rY = cssValueToDeviceIndependentPixels(arr[1], position.bottom);
1059
+ const cX = cssValueToDeviceIndependentPixels(arr[3], position.right);
1060
+ const cY = cssValueToDeviceIndependentPixels(arr[4], position.bottom);
764
1061
  const left = cX - rX;
765
1062
  const top = cY - rY;
766
1063
  const width = rX * 2;
767
1064
  const height = rY * 2;
768
1065
  return UIBezierPath.bezierPathWithOvalInRect(CGRectMake(left, top, width, height)).CGPath;
769
1066
  }
770
- function polygonPath(value, bounds) {
1067
+ function polygonPath(value, position) {
771
1068
  const path = CGPathCreateMutable();
772
1069
  let firstPoint;
773
1070
  const arr = value.split(/[,]+/);
774
1071
  for (let i = 0; i < arr.length; i++) {
775
1072
  const xy = arr[i].trim().split(/[\s]+/);
776
1073
  const point = {
777
- x: cssValueToDeviceIndependentPixels(xy[0], bounds.right),
778
- y: cssValueToDeviceIndependentPixels(xy[1], bounds.bottom),
1074
+ x: cssValueToDeviceIndependentPixels(xy[0], position.right),
1075
+ y: cssValueToDeviceIndependentPixels(xy[1], position.bottom),
779
1076
  };
780
1077
  if (!firstPoint) {
781
1078
  firstPoint = point;