react-native-windows 0.74.12 → 0.75.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/.flowconfig +8 -2
  2. package/Common/Utilities.cpp +2 -2
  3. package/Folly/TEMP_UntilFollyUpdate/ConstexprMath.h +970 -0
  4. package/Folly/TEMP_UntilFollyUpdate/json.cpp +1110 -0
  5. package/Folly/TEMP_UntilFollyUpdate/lang/ToAscii.cpp +4 -2
  6. package/Libraries/Animated/AnimatedImplementation.js +2 -0
  7. package/Libraries/Animated/NativeAnimatedHelper.js +4 -0
  8. package/Libraries/Animated/createAnimatedComponent.js +10 -4
  9. package/Libraries/Animated/useAnimatedProps.js +56 -28
  10. package/Libraries/BatchedBridge/MessageQueue.js +1 -0
  11. package/Libraries/Components/Button.js +10 -5
  12. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +11 -2
  13. package/Libraries/Components/Flyout/Flyout.js +10 -10
  14. package/Libraries/Components/Flyout/FlyoutNativeComponent.js +8 -7
  15. package/Libraries/Components/Pressable/Pressable.js +13 -6
  16. package/Libraries/Components/Pressable/Pressable.windows.js +13 -6
  17. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +4 -0
  18. package/Libraries/Components/ScrollView/ScrollView.js +109 -29
  19. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +6 -0
  20. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.windows.js +6 -0
  21. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +13 -1
  22. package/Libraries/Components/StatusBar/StatusBar.js +1 -21
  23. package/Libraries/Components/Switch/Switch.windows.js +2 -0
  24. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +0 -15
  25. package/Libraries/Components/TextInput/InputAccessoryView.js +10 -1
  26. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +0 -12
  27. package/Libraries/Components/TextInput/TextInput.d.ts +0 -19
  28. package/Libraries/Components/TextInput/TextInput.js +14 -70
  29. package/Libraries/Components/TextInput/TextInput.windows.js +15 -72
  30. package/Libraries/Components/TextInput/WindowsTextInputNativeComponent.js +27 -12
  31. package/Libraries/Components/Touchable/Touchable.js +2 -2
  32. package/Libraries/Components/Touchable/TouchableHighlight.d.ts +4 -10
  33. package/Libraries/Components/Touchable/TouchableHighlight.js +3 -1
  34. package/Libraries/Components/Touchable/TouchableHighlight.windows.js +3 -1
  35. package/Libraries/Components/Touchable/TouchableOpacity.d.ts +4 -32
  36. package/Libraries/Components/Touchable/TouchableOpacity.js +3 -1
  37. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +3 -1
  38. package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +8 -0
  39. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +117 -111
  40. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +129 -110
  41. package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -0
  42. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  43. package/Libraries/Components/View/ReactNativeViewAttributes.windows.js +1 -0
  44. package/Libraries/Components/View/View.js +0 -11
  45. package/Libraries/Components/View/View.windows.js +0 -11
  46. package/Libraries/Components/View/ViewAccessibility.js +4 -4
  47. package/Libraries/Components/View/ViewAccessibility.windows.js +4 -4
  48. package/Libraries/Components/View/ViewPropTypes.d.ts +21 -59
  49. package/Libraries/Components/View/ViewPropTypes.js +7 -0
  50. package/Libraries/Components/View/ViewPropTypes.windows.js +7 -0
  51. package/Libraries/Core/Devtools/loadBundleFromServer.js +3 -3
  52. package/Libraries/Core/Devtools/loadBundleFromServer.windows.js +153 -0
  53. package/Libraries/Core/Devtools/parseErrorStack.js +5 -5
  54. package/Libraries/Core/Devtools/parseHermesStack.js +22 -16
  55. package/Libraries/Core/ErrorHandlers.js +116 -0
  56. package/Libraries/Core/ExceptionsManager.js +2 -2
  57. package/Libraries/Core/ReactNativeVersion.js +3 -3
  58. package/Libraries/Core/setUpDeveloperTools.js +3 -1
  59. package/Libraries/Core/setUpPerformance.js +6 -4
  60. package/Libraries/Core/setUpReactDevTools.js +70 -10
  61. package/Libraries/Core/setUpTimers.js +50 -31
  62. package/Libraries/Debugging/DebuggingOverlayRegistry.js +1 -1
  63. package/Libraries/Image/Image.android.js +23 -13
  64. package/Libraries/Image/Image.d.ts +14 -15
  65. package/Libraries/Image/Image.ios.js +21 -11
  66. package/Libraries/Image/Image.windows.js +21 -11
  67. package/Libraries/Image/ImageProps.js +16 -5
  68. package/Libraries/Image/ImageTypes.flow.js +7 -2
  69. package/Libraries/Image/ImageUtils.js +1 -0
  70. package/Libraries/Image/ImageViewNativeComponent.js +2 -1
  71. package/Libraries/Inspector/ElementBox.js +6 -3
  72. package/Libraries/Inspector/ElementProperties.js +1 -1
  73. package/Libraries/Interaction/TouchHistoryMath.js +4 -4
  74. package/Libraries/IntersectionObserver/IntersectionObserverManager.js +6 -26
  75. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  76. package/Libraries/LogBox/Data/LogBoxData.js +39 -29
  77. package/Libraries/LogBox/Data/LogBoxLog.js +114 -2
  78. package/Libraries/LogBox/Data/parseLogBoxLog.js +168 -53
  79. package/Libraries/LogBox/LogBox.js +29 -12
  80. package/Libraries/LogBox/LogBoxNotificationContainer.js +4 -0
  81. package/Libraries/LogBox/UI/LogBoxInspector.js +8 -70
  82. package/Libraries/LogBox/UI/LogBoxInspectorBody.js +87 -0
  83. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +6 -42
  84. package/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js +58 -0
  85. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +5 -66
  86. package/Libraries/LogBox/UI/LogBoxInspectorHeader.windows.js +5 -66
  87. package/Libraries/LogBox/UI/LogBoxInspectorHeaderButton.js +76 -0
  88. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js +8 -5
  89. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.windows.js +8 -5
  90. package/Libraries/LogBox/UI/LogBoxNotification.js +13 -152
  91. package/Libraries/LogBox/UI/LogBoxNotificationCountBadge.js +63 -0
  92. package/Libraries/LogBox/UI/LogBoxNotificationDismissButton.js +67 -0
  93. package/Libraries/LogBox/UI/LogBoxNotificationMessage.js +57 -0
  94. package/Libraries/NativeComponent/BaseViewConfig.android.js +5 -0
  95. package/Libraries/NativeComponent/BaseViewConfig.ios.js +5 -0
  96. package/Libraries/NativeComponent/BaseViewConfig.windows.js +5 -0
  97. package/Libraries/NativeComponent/NativeComponentRegistry.js +12 -5
  98. package/Libraries/NativeComponent/StaticViewConfigValidator.js +3 -0
  99. package/Libraries/Network/XMLHttpRequest.js +5 -1
  100. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +3 -3
  101. package/Libraries/Pressability/Pressability.js +3 -51
  102. package/Libraries/Pressability/Pressability.windows.js +3 -51
  103. package/Libraries/ReactNative/AppRegistry.d.ts +4 -0
  104. package/Libraries/ReactNative/AppRegistry.js +2 -4
  105. package/Libraries/ReactNative/BridgelessUIManager.js +1 -21
  106. package/Libraries/ReactNative/FabricUIManager.js +0 -51
  107. package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +1 -0
  108. package/Libraries/ReactNative/RendererImplementation.js +20 -2
  109. package/Libraries/ReactNative/UIManager.d.ts +0 -21
  110. package/Libraries/ReactNative/UIManagerProperties.js +0 -3
  111. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +5 -341
  112. package/Libraries/ReactNative/getNativeComponentAttributes.js +8 -8
  113. package/Libraries/Renderer/implementations/ReactFabric-dev.js +15682 -27088
  114. package/Libraries/Renderer/implementations/ReactFabric-prod.js +5082 -4381
  115. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3480 -2571
  116. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +15943 -27543
  117. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5303 -4606
  118. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3450 -2572
  119. package/Libraries/Renderer/shims/ReactFabric.js +2 -2
  120. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -2
  121. package/Libraries/Renderer/shims/ReactNative.js +2 -3
  122. package/Libraries/Renderer/shims/ReactNativeTypes.js +24 -3
  123. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +2 -2
  124. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  125. package/Libraries/Share/Share.d.ts +16 -10
  126. package/Libraries/Share/Share.js +14 -15
  127. package/Libraries/StyleSheet/StyleSheet.d.ts +1 -1
  128. package/Libraries/StyleSheet/StyleSheet.js +3 -10
  129. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +21 -21
  130. package/Libraries/StyleSheet/StyleSheetTypes.js +24 -18
  131. package/Libraries/StyleSheet/flattenStyle.js +1 -0
  132. package/Libraries/StyleSheet/processFilter.js +132 -0
  133. package/Libraries/StyleSheet/processTransform.js +18 -3
  134. package/Libraries/Text/Text.js +151 -128
  135. package/Libraries/Text/Text.windows.js +144 -128
  136. package/Libraries/Text/TextNativeComponent.js +5 -4
  137. package/Libraries/Text/TextProps.js +6 -6
  138. package/Libraries/Text/TextProps.windows.js +6 -6
  139. package/Libraries/TurboModule/TurboModuleRegistry.js +2 -1
  140. package/Libraries/Types/CodegenTypes.js +3 -0
  141. package/Libraries/Utilities/{LoadingView.android.js → DevLoadingView.js} +33 -11
  142. package/Libraries/Utilities/Dimensions.js +1 -0
  143. package/Libraries/Utilities/HMRClient.js +36 -8
  144. package/Libraries/Utilities/HMRClientProdShim.js +1 -0
  145. package/Libraries/Utilities/NativePlatformConstantsWin.js +2 -2
  146. package/Libraries/Utilities/Platform.android.js +4 -4
  147. package/Libraries/Utilities/RCTLog.js +1 -0
  148. package/Libraries/Utilities/ReactNativeTestTools.js +12 -24
  149. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +11 -6
  150. package/Libraries/__tests__/ViewWindows-test.js +6 -6
  151. package/Libraries/promiseRejectionTrackingOptions.js +1 -0
  152. package/Microsoft.ReactNative/Base/FollyIncludes.h +1 -1
  153. package/Microsoft.ReactNative/ComponentView.idl +0 -17
  154. package/Microsoft.ReactNative/Composition.Input.idl +3 -3
  155. package/Microsoft.ReactNative/CompositionSwitcher.idl +0 -1
  156. package/Microsoft.ReactNative/Fabric/AbiState.cpp +3 -45
  157. package/Microsoft.ReactNative/Fabric/AbiState.h +0 -6
  158. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +0 -3
  159. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.cpp +2 -2
  160. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.h +4 -4
  161. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +0 -10
  162. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +27 -16
  163. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -1
  164. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +48 -85
  165. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +0 -4
  166. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +24 -24
  167. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +6 -8
  168. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +0 -10
  169. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +0 -3
  170. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +29 -45
  171. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +1 -3
  172. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +6 -43
  173. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +23 -34
  174. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +1 -2
  175. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +9 -3
  176. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.h +1 -1
  177. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +17 -48
  178. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +3 -7
  179. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +23 -16
  180. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +5 -2
  181. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.cpp +2 -10
  182. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +107 -36
  183. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +18 -12
  184. package/Microsoft.ReactNative/Modules/DevSettingsModule.cpp +4 -0
  185. package/Microsoft.ReactNative/Modules/DevSettingsModule.h +1 -0
  186. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -2
  187. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +7 -4
  188. package/Microsoft.ReactNative/Modules/NativeUIManager.h +1 -1
  189. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp +2 -2
  190. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.h +3 -3
  191. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +13 -20
  192. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
  193. package/Microsoft.ReactNative/Timer.idl +1 -3
  194. package/Microsoft.ReactNative/Utils/BatchingEventEmitter.cpp +1 -1
  195. package/Microsoft.ReactNative/Utils/LocalBundleReader.cpp +2 -3
  196. package/Microsoft.ReactNative/Utils/ValueUtils.cpp +1 -1
  197. package/Microsoft.ReactNative/Views/DynamicAutomationPeer.cpp +2 -2
  198. package/Microsoft.ReactNative/Views/TextInputViewManager.cpp +1 -1
  199. package/Microsoft.ReactNative/packages.lock.json +41 -78
  200. package/Microsoft.ReactNative.Cxx/JSI/LongLivedJsiValue.h +1 -1
  201. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +5 -0
  202. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +1 -0
  203. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp +14 -6
  204. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +2 -2
  205. package/Microsoft.ReactNative.Managed/Microsoft.ReactNative.Managed.csproj +1 -1
  206. package/Microsoft.ReactNative.Managed/packages.lock.json +3 -3
  207. package/PropertySheets/External/Microsoft.ReactNative.WindowsSdk.Default.props +4 -4
  208. package/PropertySheets/Generated/PackageVersion.g.props +4 -4
  209. package/README.md +21 -21
  210. package/ReactCommon/ReactCommon.vcxproj +2 -0
  211. package/ReactCommon/ReactCommon.vcxproj.filters +3 -0
  212. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +67 -0
  213. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.h +180 -0
  214. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +351 -0
  215. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +6 -3
  216. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Base.h +152 -0
  217. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Bridging.h +2 -1
  218. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/CallbackWrapper.h +13 -15
  219. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/EventEmitter.h +137 -0
  220. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Function.h +283 -0
  221. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.cpp +7 -10
  222. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +162 -0
  223. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleUtils.h +2 -4
  224. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/scrollview/ScrollViewProps.cpp +33 -8
  225. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.cpp +45 -0
  226. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.h +67 -0
  227. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +104 -74
  228. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +4 -0
  229. package/Scripts/rnw-dependencies.ps1 +36 -23
  230. package/Shared/HermesRuntimeHolder.cpp +19 -1
  231. package/Shared/HermesRuntimeHolder.h +8 -1
  232. package/Shared/HermesSamplingProfiler.cpp +1 -2
  233. package/Shared/Networking/WinRTWebSocketResource.cpp +3 -3
  234. package/Shared/OInstance.cpp +1 -2
  235. package/Shared/Shared.vcxitems +21 -15
  236. package/Shared/Shared.vcxitems.filters +8 -3
  237. package/Shared/Threading/BatchingQueueThread.cpp +6 -2
  238. package/Shared/Threading/BatchingQueueThread.h +2 -2
  239. package/Shared/Utils/CppWinrtLessExceptions.h +2 -2
  240. package/codegen/NativeAppStateSpec.g.h +8 -8
  241. package/codegen/NativeBlobModuleSpec.g.h +0 -10
  242. package/codegen/NativeDOMSpec.g.h +136 -0
  243. package/codegen/NativeDevSettingsSpec.g.h +11 -5
  244. package/codegen/NativeIdleCallbacksSpec.g.h +64 -0
  245. package/codegen/NativeIntersectionObserverSpec.g.h +14 -14
  246. package/codegen/NativeMicrotasksSpec.g.h +34 -0
  247. package/codegen/NativePerformanceSpec.g.h +35 -7
  248. package/codegen/NativePlatformConstantsWindowsSpec.g.h +81 -0
  249. package/codegen/NativePushNotificationManagerIOSSpec.g.h +15 -19
  250. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +111 -39
  251. package/codegen/NativeUIManagerSpec.g.h +5 -17
  252. package/codegen/react/components/rnwcore/Props.cpp +1 -1
  253. package/codegen/react/components/rnwcore/Props.h +16 -12
  254. package/codegen/react/components/rnwcore/States.h +0 -26
  255. package/codegen/rnwcoreJSI-generated.cpp +688 -463
  256. package/codegen/rnwcoreJSI.h +1374 -2867
  257. package/fmt/TEMP_UntilFmtUpdate/core.h +2925 -0
  258. package/fmt/fmt.vcxproj +1 -1
  259. package/jest/mockComponent.js +7 -0
  260. package/jest/renderer.js +25 -14
  261. package/jest/setup.js +19 -13
  262. package/package.json +29 -27
  263. package/rn-get-polyfills.js +1 -0
  264. package/src/private/core/composeStyles.js +27 -0
  265. package/src/private/featureflags/ReactNativeFeatureFlags.js +93 -33
  266. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  267. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +56 -0
  268. package/src/private/fusebox/setUpFuseboxReactDevToolsDispatcher.js +108 -0
  269. package/src/private/specs/modules/NativeBlobModule.js +4 -2
  270. package/src/private/specs/modules/NativeDevSettings.js +1 -0
  271. package/src/private/specs/modules/NativePushNotificationManagerIOS.js +0 -4
  272. package/src/private/specs/modules/NativeUIManager.js +0 -7
  273. package/src/private/webapis/dom/geometry/DOMRectReadOnly.js +24 -24
  274. package/src/private/webapis/dom/nodes/ReactNativeElement.js +11 -14
  275. package/src/private/webapis/dom/nodes/ReadOnlyCharacterData.js +2 -3
  276. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +24 -54
  277. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +5 -13
  278. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +468 -0
  279. package/src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock.js +413 -0
  280. package/src/private/webapis/dom/oldstylecollections/DOMRectList.js +4 -4
  281. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +4 -4
  282. package/src/private/webapis/dom/oldstylecollections/NodeList.js +5 -5
  283. package/src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks.js +34 -0
  284. package/src/private/webapis/microtasks/specs/NativeMicrotasks.js +21 -0
  285. package/src/private/webapis/performance/EventCounts.js +1 -1
  286. package/src/private/webapis/performance/MemoryInfo.js +9 -9
  287. package/src/private/webapis/performance/Performance.js +10 -56
  288. package/src/private/webapis/performance/PerformanceObserver.js +30 -22
  289. package/src/private/webapis/performance/RawPerformanceEntry.js +2 -7
  290. package/src/private/webapis/performance/ReactNativeStartupTiming.js +18 -18
  291. package/src/private/webapis/performance/UserTiming.js +63 -0
  292. package/src/private/webapis/performance/{NativePerformance.js → specs/NativePerformance.js} +3 -2
  293. package/src/private/webapis/performance/{NativePerformanceObserver.js → specs/NativePerformanceObserver.js} +2 -2
  294. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformance.js +1 -1
  295. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformanceObserver.js +3 -4
  296. package/stubs/glog/logging.h +1 -0
  297. package/template/cpp-lib/proj/MyLib.vcxproj +1 -1
  298. package/template/cs-lib/proj/MyLib.csproj +1 -1
  299. package/template/metro.config.js +13 -2
  300. package/templates/cpp-app/template.config.js +1 -1
  301. package/templates/cpp-lib/example/metro.config.js +2 -2
  302. package/templates/cpp-lib/template.config.js +1 -1
  303. package/templates/old/generateWrapper.js +4 -1
  304. package/types/modules/globals.d.ts +4 -0
  305. package/Libraries/Lists/FlatList.windows.js +0 -717
  306. package/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js +0 -13
  307. package/Libraries/Utilities/LoadingView.ios.js +0 -50
  308. package/Libraries/Utilities/LoadingView.js +0 -16
  309. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +0 -178
  310. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.cpp +0 -39
  311. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.h +0 -31
  312. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGEnums.h +0 -137
  313. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/algorithm/CalculateLayout.cpp +0 -2377
  314. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.cpp +0 -140
  315. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h +0 -92
  316. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/ExperimentalFeature.h +0 -40
  317. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.cpp +0 -48
  318. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h +0 -122
  319. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/Node.cpp +0 -366
  320. package/codegen/NativeAnimationsDebugModuleSpec.g.h +0 -40
  321. package/codegen/NativePlatformConstantsWinSpec.g.h +0 -81
  322. package/jest/ReactNativeInternalFeatureFlagsMock.js +0 -13
  323. package/src/private/featureflags/NativeReactNativeFeatureFlags.js +0 -44
  324. package/src/private/featureflags/__tests__/ReactNativeFeatureFlags-test.js +0 -92
  325. package/src/private/specs/modules/NativeAnimationsDebugModule.js +0 -20
  326. package/src/private/webapis/dom/oldstylecollections/__tests__/DOMRectList-test.js +0 -85
  327. package/src/private/webapis/dom/oldstylecollections/__tests__/HTMLCollection-test.js +0 -80
  328. package/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-test.js +0 -161
  329. package/src/private/webapis/performance/__tests__/EventCounts-test.js +0 -116
  330. package/src/private/webapis/performance/__tests__/NativePerformanceMock-test.js +0 -82
  331. package/src/private/webapis/performance/__tests__/NativePerformanceObserverMock-test.js +0 -108
  332. package/src/private/webapis/performance/__tests__/Performance-test.js +0 -117
  333. package/src/private/webapis/performance/__tests__/PerformanceObserver-test.js +0 -208
  334. package/template/metro.devMode.config.js +0 -56
  335. /package/src/private/specs/modules/{NativePlatformConstantsWin.js → NativePlatformConstantsWindows.js} +0 -0
@@ -1,2377 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #include <algorithm>
9
- #include <atomic>
10
- #include <cfloat>
11
- #include <cmath>
12
- #include <cstring>
13
-
14
- #include <yoga/Yoga.h>
15
-
16
- #include <yoga/algorithm/AbsoluteLayout.h>
17
- #include <yoga/algorithm/Align.h>
18
- #include <yoga/algorithm/Baseline.h>
19
- #include <yoga/algorithm/BoundAxis.h>
20
- #include <yoga/algorithm/Cache.h>
21
- #include <yoga/algorithm/CalculateLayout.h>
22
- #include <yoga/algorithm/FlexDirection.h>
23
- #include <yoga/algorithm/FlexLine.h>
24
- #include <yoga/algorithm/PixelGrid.h>
25
- #include <yoga/algorithm/SizingMode.h>
26
- #include <yoga/algorithm/TrailingPosition.h>
27
- #include <yoga/debug/AssertFatal.h>
28
- #include <yoga/debug/Log.h>
29
- #include <yoga/event/event.h>
30
- #include <yoga/node/Node.h>
31
- #include <yoga/numeric/Comparison.h>
32
- #include <yoga/numeric/FloatOptional.h>
33
-
34
- namespace facebook::yoga {
35
-
36
- std::atomic<uint32_t> gCurrentGenerationCount(0);
37
-
38
- static void constrainMaxSizeForMode(
39
- const yoga::Node* node,
40
- FlexDirection axis,
41
- float ownerAxisSize,
42
- float ownerWidth,
43
- /*in_out*/ SizingMode* mode,
44
- /*in_out*/ float* size) {
45
- const FloatOptional maxSize =
46
- node->style().maxDimension(dimension(axis)).resolve(ownerAxisSize) +
47
- FloatOptional(node->style().computeMarginForAxis(axis, ownerWidth));
48
- switch (*mode) {
49
- case SizingMode::StretchFit:
50
- case SizingMode::FitContent:
51
- *size = (maxSize.isUndefined() || *size < maxSize.unwrap())
52
- ? *size
53
- : maxSize.unwrap();
54
- break;
55
- case SizingMode::MaxContent:
56
- if (maxSize.isDefined()) {
57
- *mode = SizingMode::FitContent;
58
- *size = maxSize.unwrap();
59
- }
60
- break;
61
- }
62
- }
63
-
64
- static void computeFlexBasisForChild(
65
- const yoga::Node* const node,
66
- yoga::Node* const child,
67
- const float width,
68
- const SizingMode widthMode,
69
- const float height,
70
- const float ownerWidth,
71
- const float ownerHeight,
72
- const SizingMode heightMode,
73
- const Direction direction,
74
- LayoutData& layoutMarkerData,
75
- const uint32_t depth,
76
- const uint32_t generationCount) {
77
- const FlexDirection mainAxis =
78
- resolveDirection(node->style().flexDirection(), direction);
79
- const bool isMainAxisRow = isRow(mainAxis);
80
- const float mainAxisSize = isMainAxisRow ? width : height;
81
- const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight;
82
-
83
- float childWidth;
84
- float childHeight;
85
- SizingMode childWidthSizingMode;
86
- SizingMode childHeightSizingMode;
87
-
88
- const FloatOptional resolvedFlexBasis =
89
- child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
90
- const bool isRowStyleDimDefined =
91
- child->hasDefiniteLength(Dimension::Width, ownerWidth);
92
- const bool isColumnStyleDimDefined =
93
- child->hasDefiniteLength(Dimension::Height, ownerHeight);
94
-
95
- if (resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize)) {
96
- if (child->getLayout().computedFlexBasis.isUndefined() ||
97
- (child->getConfig()->isExperimentalFeatureEnabled(
98
- ExperimentalFeature::WebFlexBasis) &&
99
- child->getLayout().computedFlexBasisGeneration != generationCount)) {
100
- const FloatOptional paddingAndBorder =
101
- FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
102
- child->setLayoutComputedFlexBasis(
103
- yoga::maxOrDefined(resolvedFlexBasis, paddingAndBorder));
104
- }
105
- } else if (isMainAxisRow && isRowStyleDimDefined) {
106
- // The width is definite, so use that as the flex basis.
107
- const FloatOptional paddingAndBorder = FloatOptional(
108
- paddingAndBorderForAxis(child, FlexDirection::Row, ownerWidth));
109
-
110
- child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
111
- child->getResolvedDimension(Dimension::Width).resolve(ownerWidth),
112
- paddingAndBorder));
113
- } else if (!isMainAxisRow && isColumnStyleDimDefined) {
114
- // The height is definite, so use that as the flex basis.
115
- const FloatOptional paddingAndBorder = FloatOptional(
116
- paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
117
- child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
118
- child->getResolvedDimension(Dimension::Height).resolve(ownerHeight),
119
- paddingAndBorder));
120
- } else {
121
- // Compute the flex basis and hypothetical main size (i.e. the clamped flex
122
- // basis).
123
- childWidth = YGUndefined;
124
- childHeight = YGUndefined;
125
- childWidthSizingMode = SizingMode::MaxContent;
126
- childHeightSizingMode = SizingMode::MaxContent;
127
-
128
- auto marginRow =
129
- child->style().computeMarginForAxis(FlexDirection::Row, ownerWidth);
130
- auto marginColumn =
131
- child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
132
-
133
- if (isRowStyleDimDefined) {
134
- childWidth = child->getResolvedDimension(Dimension::Width)
135
- .resolve(ownerWidth)
136
- .unwrap() +
137
- marginRow;
138
- childWidthSizingMode = SizingMode::StretchFit;
139
- }
140
- if (isColumnStyleDimDefined) {
141
- childHeight = child->getResolvedDimension(Dimension::Height)
142
- .resolve(ownerHeight)
143
- .unwrap() +
144
- marginColumn;
145
- childHeightSizingMode = SizingMode::StretchFit;
146
- }
147
-
148
- // The W3C spec doesn't say anything about the 'overflow' property, but all
149
- // major browsers appear to implement the following logic.
150
- if ((!isMainAxisRow && node->style().overflow() == Overflow::Scroll) ||
151
- node->style().overflow() != Overflow::Scroll) {
152
- if (yoga::isUndefined(childWidth) && yoga::isDefined(width)) {
153
- childWidth = width;
154
- childWidthSizingMode = SizingMode::FitContent;
155
- }
156
- }
157
-
158
- if ((isMainAxisRow && node->style().overflow() == Overflow::Scroll) ||
159
- node->style().overflow() != Overflow::Scroll) {
160
- if (yoga::isUndefined(childHeight) && yoga::isDefined(height)) {
161
- childHeight = height;
162
- childHeightSizingMode = SizingMode::FitContent;
163
- }
164
- }
165
-
166
- const auto& childStyle = child->style();
167
- if (childStyle.aspectRatio().isDefined()) {
168
- if (!isMainAxisRow && childWidthSizingMode == SizingMode::StretchFit) {
169
- childHeight = marginColumn +
170
- (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
171
- childHeightSizingMode = SizingMode::StretchFit;
172
- } else if (
173
- isMainAxisRow && childHeightSizingMode == SizingMode::StretchFit) {
174
- childWidth = marginRow +
175
- (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
176
- childWidthSizingMode = SizingMode::StretchFit;
177
- }
178
- }
179
-
180
- // If child has no defined size in the cross axis and is set to stretch, set
181
- // the cross axis to be measured exactly with the available inner width
182
-
183
- const bool hasExactWidth =
184
- yoga::isDefined(width) && widthMode == SizingMode::StretchFit;
185
- const bool childWidthStretch =
186
- resolveChildAlignment(node, child) == Align::Stretch &&
187
- childWidthSizingMode != SizingMode::StretchFit;
188
- if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth &&
189
- childWidthStretch) {
190
- childWidth = width;
191
- childWidthSizingMode = SizingMode::StretchFit;
192
- if (childStyle.aspectRatio().isDefined()) {
193
- childHeight =
194
- (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
195
- childHeightSizingMode = SizingMode::StretchFit;
196
- }
197
- }
198
-
199
- const bool hasExactHeight =
200
- yoga::isDefined(height) && heightMode == SizingMode::StretchFit;
201
- const bool childHeightStretch =
202
- resolveChildAlignment(node, child) == Align::Stretch &&
203
- childHeightSizingMode != SizingMode::StretchFit;
204
- if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight &&
205
- childHeightStretch) {
206
- childHeight = height;
207
- childHeightSizingMode = SizingMode::StretchFit;
208
-
209
- if (childStyle.aspectRatio().isDefined()) {
210
- childWidth =
211
- (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
212
- childWidthSizingMode = SizingMode::StretchFit;
213
- }
214
- }
215
-
216
- constrainMaxSizeForMode(
217
- child,
218
- FlexDirection::Row,
219
- ownerWidth,
220
- ownerWidth,
221
- &childWidthSizingMode,
222
- &childWidth);
223
- constrainMaxSizeForMode(
224
- child,
225
- FlexDirection::Column,
226
- ownerHeight,
227
- ownerWidth,
228
- &childHeightSizingMode,
229
- &childHeight);
230
-
231
- // Measure the child
232
- calculateLayoutInternal(
233
- child,
234
- childWidth,
235
- childHeight,
236
- direction,
237
- childWidthSizingMode,
238
- childHeightSizingMode,
239
- ownerWidth,
240
- ownerHeight,
241
- false,
242
- LayoutPassReason::kMeasureChild,
243
- layoutMarkerData,
244
- depth,
245
- generationCount);
246
-
247
- child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
248
- child->getLayout().measuredDimension(dimension(mainAxis)),
249
- paddingAndBorderForAxis(child, mainAxis, ownerWidth))));
250
- }
251
- child->setLayoutComputedFlexBasisGeneration(generationCount);
252
- }
253
-
254
- static void measureNodeWithMeasureFunc(
255
- yoga::Node* const node,
256
- float availableWidth,
257
- float availableHeight,
258
- const SizingMode widthSizingMode,
259
- const SizingMode heightSizingMode,
260
- const float ownerWidth,
261
- const float ownerHeight,
262
- LayoutData& layoutMarkerData,
263
- const LayoutPassReason reason) {
264
- yoga::assertFatalWithNode(
265
- node,
266
- node->hasMeasureFunc(),
267
- "Expected node to have custom measure function");
268
-
269
- if (widthSizingMode == SizingMode::MaxContent) {
270
- availableWidth = YGUndefined;
271
- }
272
- if (heightSizingMode == SizingMode::MaxContent) {
273
- availableHeight = YGUndefined;
274
- }
275
-
276
- const auto& layout = node->getLayout();
277
- const float paddingAndBorderAxisRow = layout.padding(PhysicalEdge::Left) +
278
- layout.padding(PhysicalEdge::Right) + layout.border(PhysicalEdge::Left) +
279
- layout.border(PhysicalEdge::Right);
280
- const float paddingAndBorderAxisColumn = layout.padding(PhysicalEdge::Top) +
281
- layout.padding(PhysicalEdge::Bottom) + layout.border(PhysicalEdge::Top) +
282
- layout.border(PhysicalEdge::Bottom);
283
-
284
- // We want to make sure we don't call measure with negative size
285
- const float innerWidth = yoga::isUndefined(availableWidth)
286
- ? availableWidth
287
- : yoga::maxOrDefined(0.0f, availableWidth - paddingAndBorderAxisRow);
288
- const float innerHeight = yoga::isUndefined(availableHeight)
289
- ? availableHeight
290
- : yoga::maxOrDefined(0.0f, availableHeight - paddingAndBorderAxisColumn);
291
-
292
- if (widthSizingMode == SizingMode::StretchFit &&
293
- heightSizingMode == SizingMode::StretchFit &&
294
- !YGConfigIsExperimentalFeatureEnabled( // [Win] YGExperimentalFeatureCallMeasureCallbackOnAllNodes check added for NetUI
295
- node->getConfig(), YGExperimentalFeatureCallMeasureCallbackOnAllNodes)) {
296
- // Don't bother sizing the text if both dimensions are already defined.
297
- node->setLayoutMeasuredDimension(
298
- boundAxis(
299
- node, FlexDirection::Row, availableWidth, ownerWidth, ownerWidth),
300
- Dimension::Width);
301
- node->setLayoutMeasuredDimension(
302
- boundAxis(
303
- node,
304
- FlexDirection::Column,
305
- availableHeight,
306
- ownerHeight,
307
- ownerWidth),
308
- Dimension::Height);
309
- } else {
310
- Event::publish<Event::MeasureCallbackStart>(node);
311
-
312
- // Measure the text under the current constraints.
313
- const YGSize measuredSize = node->measure(
314
- innerWidth,
315
- measureMode(widthSizingMode),
316
- innerHeight,
317
- measureMode(heightSizingMode));
318
-
319
- layoutMarkerData.measureCallbacks += 1;
320
- layoutMarkerData.measureCallbackReasonsCount[static_cast<size_t>(reason)] +=
321
- 1;
322
-
323
- Event::publish<Event::MeasureCallbackEnd>(
324
- node,
325
- {innerWidth,
326
- unscopedEnum(measureMode(widthSizingMode)),
327
- innerHeight,
328
- unscopedEnum(measureMode(heightSizingMode)),
329
- measuredSize.width,
330
- measuredSize.height,
331
- reason});
332
-
333
- node->setLayoutMeasuredDimension(
334
- boundAxis(
335
- node,
336
- FlexDirection::Row,
337
- (widthSizingMode == SizingMode::MaxContent ||
338
- widthSizingMode == SizingMode::FitContent)
339
- ? measuredSize.width + paddingAndBorderAxisRow
340
- : availableWidth,
341
- ownerWidth,
342
- ownerWidth),
343
- Dimension::Width);
344
-
345
- node->setLayoutMeasuredDimension(
346
- boundAxis(
347
- node,
348
- FlexDirection::Column,
349
- (heightSizingMode == SizingMode::MaxContent ||
350
- heightSizingMode == SizingMode::FitContent)
351
- ? measuredSize.height + paddingAndBorderAxisColumn
352
- : availableHeight,
353
- ownerHeight,
354
- ownerWidth),
355
- Dimension::Height);
356
- }
357
- }
358
-
359
- // For nodes with no children, use the available values if they were provided,
360
- // or the minimum size as indicated by the padding and border sizes.
361
- static void measureNodeWithoutChildren(
362
- yoga::Node* const node,
363
- const float availableWidth,
364
- const float availableHeight,
365
- const SizingMode widthSizingMode,
366
- const SizingMode heightSizingMode,
367
- const float ownerWidth,
368
- const float ownerHeight) {
369
- const auto& layout = node->getLayout();
370
-
371
- float width = availableWidth;
372
- if (widthSizingMode == SizingMode::MaxContent ||
373
- widthSizingMode == SizingMode::FitContent) {
374
- width = layout.padding(PhysicalEdge::Left) +
375
- layout.padding(PhysicalEdge::Right) +
376
- layout.border(PhysicalEdge::Left) + layout.border(PhysicalEdge::Right);
377
- }
378
- node->setLayoutMeasuredDimension(
379
- boundAxis(node, FlexDirection::Row, width, ownerWidth, ownerWidth),
380
- Dimension::Width);
381
-
382
- float height = availableHeight;
383
- if (heightSizingMode == SizingMode::MaxContent ||
384
- heightSizingMode == SizingMode::FitContent) {
385
- height = layout.padding(PhysicalEdge::Top) +
386
- layout.padding(PhysicalEdge::Bottom) +
387
- layout.border(PhysicalEdge::Top) + layout.border(PhysicalEdge::Bottom);
388
- }
389
- node->setLayoutMeasuredDimension(
390
- boundAxis(node, FlexDirection::Column, height, ownerHeight, ownerWidth),
391
- Dimension::Height);
392
- }
393
-
394
- static bool measureNodeWithFixedSize(
395
- yoga::Node* const node,
396
- const float availableWidth,
397
- const float availableHeight,
398
- const SizingMode widthSizingMode,
399
- const SizingMode heightSizingMode,
400
- const float ownerWidth,
401
- const float ownerHeight) {
402
- if ((yoga::isDefined(availableWidth) &&
403
- widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) ||
404
- (yoga::isDefined(availableHeight) &&
405
- heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) ||
406
- (widthSizingMode == SizingMode::StretchFit &&
407
- heightSizingMode == SizingMode::StretchFit)) {
408
- node->setLayoutMeasuredDimension(
409
- boundAxis(
410
- node,
411
- FlexDirection::Row,
412
- yoga::isUndefined(availableWidth) ||
413
- (widthSizingMode == SizingMode::FitContent &&
414
- availableWidth < 0.0f)
415
- ? 0.0f
416
- : availableWidth,
417
- ownerWidth,
418
- ownerWidth),
419
- Dimension::Width);
420
-
421
- node->setLayoutMeasuredDimension(
422
- boundAxis(
423
- node,
424
- FlexDirection::Column,
425
- yoga::isUndefined(availableHeight) ||
426
- (heightSizingMode == SizingMode::FitContent &&
427
- availableHeight < 0.0f)
428
- ? 0.0f
429
- : availableHeight,
430
- ownerHeight,
431
- ownerWidth),
432
- Dimension::Height);
433
- return true;
434
- }
435
-
436
- return false;
437
- }
438
-
439
- static void zeroOutLayoutRecursively(yoga::Node* const node) {
440
- node->getLayout() = {};
441
- node->setLayoutDimension(0, Dimension::Width);
442
- node->setLayoutDimension(0, Dimension::Height);
443
- node->setHasNewLayout(true);
444
-
445
- node->cloneChildrenIfNeeded();
446
- for (const auto child : node->getChildren()) {
447
- zeroOutLayoutRecursively(child);
448
- }
449
- }
450
-
451
- static float calculateAvailableInnerDimension(
452
- const yoga::Node* const node,
453
- const Dimension dimension,
454
- const float availableDim,
455
- const float paddingAndBorder,
456
- const float ownerDim) {
457
- float availableInnerDim = availableDim - paddingAndBorder;
458
- // Max dimension overrides predefined dimension value; Min dimension in turn
459
- // overrides both of the above
460
- if (yoga::isDefined(availableInnerDim)) {
461
- // We want to make sure our available height does not violate min and max
462
- // constraints
463
- const FloatOptional minDimensionOptional =
464
- node->style().minDimension(dimension).resolve(ownerDim);
465
- const float minInnerDim = minDimensionOptional.isUndefined()
466
- ? 0.0f
467
- : minDimensionOptional.unwrap() - paddingAndBorder;
468
-
469
- const FloatOptional maxDimensionOptional =
470
- node->style().maxDimension(dimension).resolve(ownerDim);
471
-
472
- const float maxInnerDim = maxDimensionOptional.isUndefined()
473
- ? FLT_MAX
474
- : maxDimensionOptional.unwrap() - paddingAndBorder;
475
- availableInnerDim = yoga::maxOrDefined(
476
- yoga::minOrDefined(availableInnerDim, maxInnerDim), minInnerDim);
477
- }
478
-
479
- return availableInnerDim;
480
- }
481
-
482
- static float computeFlexBasisForChildren(
483
- yoga::Node* const node,
484
- const float availableInnerWidth,
485
- const float availableInnerHeight,
486
- SizingMode widthSizingMode,
487
- SizingMode heightSizingMode,
488
- Direction direction,
489
- FlexDirection mainAxis,
490
- bool performLayout,
491
- LayoutData& layoutMarkerData,
492
- const uint32_t depth,
493
- const uint32_t generationCount) {
494
- float totalOuterFlexBasis = 0.0f;
495
- YGNodeRef singleFlexChild = nullptr;
496
- const auto& children = node->getChildren();
497
- SizingMode sizingModeMainDim =
498
- isRow(mainAxis) ? widthSizingMode : heightSizingMode;
499
- // If there is only one child with flexGrow + flexShrink it means we can set
500
- // the computedFlexBasis to 0 instead of measuring and shrinking / flexing the
501
- // child to exactly match the remaining space
502
- if (sizingModeMainDim == SizingMode::StretchFit) {
503
- for (auto child : children) {
504
- if (child->isNodeFlexible()) {
505
- if (singleFlexChild != nullptr ||
506
- yoga::inexactEquals(child->resolveFlexGrow(), 0.0f) ||
507
- yoga::inexactEquals(child->resolveFlexShrink(), 0.0f)) {
508
- // There is already a flexible child, or this flexible child doesn't
509
- // have flexGrow and flexShrink, abort
510
- singleFlexChild = nullptr;
511
- break;
512
- } else {
513
- singleFlexChild = child;
514
- }
515
- }
516
- }
517
- }
518
-
519
- for (auto child : children) {
520
- child->resolveDimension();
521
- if (child->style().display() == Display::None) {
522
- zeroOutLayoutRecursively(child);
523
- child->setHasNewLayout(true);
524
- child->setDirty(false);
525
- continue;
526
- }
527
- if (performLayout) {
528
- // Set the initial position (relative to the owner).
529
- const Direction childDirection = child->resolveDirection(direction);
530
- const float mainDim =
531
- isRow(mainAxis) ? availableInnerWidth : availableInnerHeight;
532
- const float crossDim =
533
- isRow(mainAxis) ? availableInnerHeight : availableInnerWidth;
534
- child->setPosition(
535
- childDirection, mainDim, crossDim, availableInnerWidth);
536
- }
537
-
538
- if (child->style().positionType() == PositionType::Absolute) {
539
- continue;
540
- }
541
- if (child == singleFlexChild) {
542
- child->setLayoutComputedFlexBasisGeneration(generationCount);
543
- child->setLayoutComputedFlexBasis(FloatOptional(0));
544
- } else {
545
- computeFlexBasisForChild(
546
- node,
547
- child,
548
- availableInnerWidth,
549
- widthSizingMode,
550
- availableInnerHeight,
551
- availableInnerWidth,
552
- availableInnerHeight,
553
- heightSizingMode,
554
- direction,
555
- layoutMarkerData,
556
- depth,
557
- generationCount);
558
- }
559
-
560
- totalOuterFlexBasis +=
561
- (child->getLayout().computedFlexBasis.unwrap() +
562
- child->style().computeMarginForAxis(mainAxis, availableInnerWidth));
563
- }
564
-
565
- return totalOuterFlexBasis;
566
- }
567
-
568
- // It distributes the free space to the flexible items and ensures that the size
569
- // of the flex items abide the min and max constraints. At the end of this
570
- // function the child nodes would have proper size. Prior using this function
571
- // please ensure that distributeFreeSpaceFirstPass is called.
572
- static float distributeFreeSpaceSecondPass(
573
- FlexLine& flexLine,
574
- yoga::Node* const node,
575
- const FlexDirection mainAxis,
576
- const FlexDirection crossAxis,
577
- const Direction direction,
578
- const float mainAxisownerSize,
579
- const float availableInnerMainDim,
580
- const float availableInnerCrossDim,
581
- const float availableInnerWidth,
582
- const float availableInnerHeight,
583
- const bool mainAxisOverflows,
584
- const SizingMode sizingModeCrossDim,
585
- const bool performLayout,
586
- LayoutData& layoutMarkerData,
587
- const uint32_t depth,
588
- const uint32_t generationCount) {
589
- float childFlexBasis = 0;
590
- float flexShrinkScaledFactor = 0;
591
- float flexGrowFactor = 0;
592
- float deltaFreeSpace = 0;
593
- const bool isMainAxisRow = isRow(mainAxis);
594
- const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap;
595
-
596
- for (auto currentLineChild : flexLine.itemsInFlow) {
597
- childFlexBasis = boundAxisWithinMinAndMax(
598
- currentLineChild,
599
- mainAxis,
600
- currentLineChild->getLayout().computedFlexBasis,
601
- mainAxisownerSize)
602
- .unwrap();
603
- float updatedMainSize = childFlexBasis;
604
-
605
- if (yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
606
- flexLine.layout.remainingFreeSpace < 0) {
607
- flexShrinkScaledFactor =
608
- -currentLineChild->resolveFlexShrink() * childFlexBasis;
609
- // Is this child able to shrink?
610
- if (flexShrinkScaledFactor != 0) {
611
- float childSize;
612
-
613
- if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
614
- flexLine.layout.totalFlexShrinkScaledFactors == 0) {
615
- childSize = childFlexBasis + flexShrinkScaledFactor;
616
- } else {
617
- childSize = childFlexBasis +
618
- (flexLine.layout.remainingFreeSpace /
619
- flexLine.layout.totalFlexShrinkScaledFactors) *
620
- flexShrinkScaledFactor;
621
- }
622
-
623
- updatedMainSize = boundAxis(
624
- currentLineChild,
625
- mainAxis,
626
- childSize,
627
- availableInnerMainDim,
628
- availableInnerWidth);
629
- }
630
- } else if (
631
- yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
632
- flexLine.layout.remainingFreeSpace > 0) {
633
- flexGrowFactor = currentLineChild->resolveFlexGrow();
634
-
635
- // Is this child able to grow?
636
- if (!std::isnan(flexGrowFactor) && flexGrowFactor != 0) {
637
- updatedMainSize = boundAxis(
638
- currentLineChild,
639
- mainAxis,
640
- childFlexBasis +
641
- flexLine.layout.remainingFreeSpace /
642
- flexLine.layout.totalFlexGrowFactors * flexGrowFactor,
643
- availableInnerMainDim,
644
- availableInnerWidth);
645
- }
646
- }
647
-
648
- deltaFreeSpace += updatedMainSize - childFlexBasis;
649
-
650
- const float marginMain = currentLineChild->style().computeMarginForAxis(
651
- mainAxis, availableInnerWidth);
652
- const float marginCross = currentLineChild->style().computeMarginForAxis(
653
- crossAxis, availableInnerWidth);
654
-
655
- float childCrossSize;
656
- float childMainSize = updatedMainSize + marginMain;
657
- SizingMode childCrossSizingMode;
658
- SizingMode childMainSizingMode = SizingMode::StretchFit;
659
-
660
- const auto& childStyle = currentLineChild->style();
661
- if (childStyle.aspectRatio().isDefined()) {
662
- childCrossSize = isMainAxisRow
663
- ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap()
664
- : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap();
665
- childCrossSizingMode = SizingMode::StretchFit;
666
-
667
- childCrossSize += marginCross;
668
- } else if (
669
- !std::isnan(availableInnerCrossDim) &&
670
- !currentLineChild->hasDefiniteLength(
671
- dimension(crossAxis), availableInnerCrossDim) &&
672
- sizingModeCrossDim == SizingMode::StretchFit &&
673
- !(isNodeFlexWrap && mainAxisOverflows) &&
674
- resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
675
- !currentLineChild->style().flexStartMarginIsAuto(
676
- crossAxis, direction) &&
677
- !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction)) {
678
- childCrossSize = availableInnerCrossDim;
679
- childCrossSizingMode = SizingMode::StretchFit;
680
- } else if (!currentLineChild->hasDefiniteLength(
681
- dimension(crossAxis), availableInnerCrossDim)) {
682
- childCrossSize = availableInnerCrossDim;
683
- childCrossSizingMode = yoga::isUndefined(childCrossSize)
684
- ? SizingMode::MaxContent
685
- : SizingMode::FitContent;
686
- } else {
687
- childCrossSize =
688
- currentLineChild->getResolvedDimension(dimension(crossAxis))
689
- .resolve(availableInnerCrossDim)
690
- .unwrap() +
691
- marginCross;
692
- const bool isLoosePercentageMeasurement =
693
- currentLineChild->getResolvedDimension(dimension(crossAxis)).unit() ==
694
- Unit::Percent &&
695
- sizingModeCrossDim != SizingMode::StretchFit;
696
- childCrossSizingMode =
697
- yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
698
- ? SizingMode::MaxContent
699
- : SizingMode::StretchFit;
700
- }
701
-
702
- constrainMaxSizeForMode(
703
- currentLineChild,
704
- mainAxis,
705
- availableInnerMainDim,
706
- availableInnerWidth,
707
- &childMainSizingMode,
708
- &childMainSize);
709
- constrainMaxSizeForMode(
710
- currentLineChild,
711
- crossAxis,
712
- availableInnerCrossDim,
713
- availableInnerWidth,
714
- &childCrossSizingMode,
715
- &childCrossSize);
716
-
717
- const bool requiresStretchLayout =
718
- !currentLineChild->hasDefiniteLength(
719
- dimension(crossAxis), availableInnerCrossDim) &&
720
- resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
721
- !currentLineChild->style().flexStartMarginIsAuto(
722
- crossAxis, direction) &&
723
- !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction);
724
-
725
- const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
726
- const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
727
-
728
- const SizingMode childWidthSizingMode =
729
- isMainAxisRow ? childMainSizingMode : childCrossSizingMode;
730
- const SizingMode childHeightSizingMode =
731
- !isMainAxisRow ? childMainSizingMode : childCrossSizingMode;
732
-
733
- const bool isLayoutPass = performLayout && !requiresStretchLayout;
734
- // Recursively call the layout algorithm for this child with the updated
735
- // main size.
736
- calculateLayoutInternal(
737
- currentLineChild,
738
- childWidth,
739
- childHeight,
740
- node->getLayout().direction(),
741
- childWidthSizingMode,
742
- childHeightSizingMode,
743
- availableInnerWidth,
744
- availableInnerHeight,
745
- isLayoutPass,
746
- isLayoutPass ? LayoutPassReason::kFlexLayout
747
- : LayoutPassReason::kFlexMeasure,
748
- layoutMarkerData,
749
- depth,
750
- generationCount);
751
- node->setLayoutHadOverflow(
752
- node->getLayout().hadOverflow() ||
753
- currentLineChild->getLayout().hadOverflow());
754
- }
755
- return deltaFreeSpace;
756
- }
757
-
758
- // It distributes the free space to the flexible items.For those flexible items
759
- // whose min and max constraints are triggered, those flex item's clamped size
760
- // is removed from the remaingfreespace.
761
- static void distributeFreeSpaceFirstPass(
762
- FlexLine& flexLine,
763
- const FlexDirection mainAxis,
764
- const float mainAxisownerSize,
765
- const float availableInnerMainDim,
766
- const float availableInnerWidth) {
767
- float flexShrinkScaledFactor = 0;
768
- float flexGrowFactor = 0;
769
- float baseMainSize = 0;
770
- float boundMainSize = 0;
771
- float deltaFreeSpace = 0;
772
-
773
- for (auto currentLineChild : flexLine.itemsInFlow) {
774
- float childFlexBasis = boundAxisWithinMinAndMax(
775
- currentLineChild,
776
- mainAxis,
777
- currentLineChild->getLayout().computedFlexBasis,
778
- mainAxisownerSize)
779
- .unwrap();
780
-
781
- if (flexLine.layout.remainingFreeSpace < 0) {
782
- flexShrinkScaledFactor =
783
- -currentLineChild->resolveFlexShrink() * childFlexBasis;
784
-
785
- // Is this child able to shrink?
786
- if (yoga::isDefined(flexShrinkScaledFactor) &&
787
- flexShrinkScaledFactor != 0) {
788
- baseMainSize = childFlexBasis +
789
- flexLine.layout.remainingFreeSpace /
790
- flexLine.layout.totalFlexShrinkScaledFactors *
791
- flexShrinkScaledFactor;
792
- boundMainSize = boundAxis(
793
- currentLineChild,
794
- mainAxis,
795
- baseMainSize,
796
- availableInnerMainDim,
797
- availableInnerWidth);
798
- if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) &&
799
- baseMainSize != boundMainSize) {
800
- // By excluding this item's size and flex factor from remaining, this
801
- // item's min/max constraints should also trigger in the second pass
802
- // resulting in the item's size calculation being identical in the
803
- // first and second passes.
804
- deltaFreeSpace += boundMainSize - childFlexBasis;
805
- flexLine.layout.totalFlexShrinkScaledFactors -=
806
- (-currentLineChild->resolveFlexShrink() *
807
- currentLineChild->getLayout().computedFlexBasis.unwrap());
808
- }
809
- }
810
- } else if (
811
- yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
812
- flexLine.layout.remainingFreeSpace > 0) {
813
- flexGrowFactor = currentLineChild->resolveFlexGrow();
814
-
815
- // Is this child able to grow?
816
- if (yoga::isDefined(flexGrowFactor) && flexGrowFactor != 0) {
817
- baseMainSize = childFlexBasis +
818
- flexLine.layout.remainingFreeSpace /
819
- flexLine.layout.totalFlexGrowFactors * flexGrowFactor;
820
- boundMainSize = boundAxis(
821
- currentLineChild,
822
- mainAxis,
823
- baseMainSize,
824
- availableInnerMainDim,
825
- availableInnerWidth);
826
-
827
- if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) &&
828
- baseMainSize != boundMainSize) {
829
- // By excluding this item's size and flex factor from remaining, this
830
- // item's min/max constraints should also trigger in the second pass
831
- // resulting in the item's size calculation being identical in the
832
- // first and second passes.
833
- deltaFreeSpace += boundMainSize - childFlexBasis;
834
- flexLine.layout.totalFlexGrowFactors -= flexGrowFactor;
835
- }
836
- }
837
- }
838
- }
839
- flexLine.layout.remainingFreeSpace -= deltaFreeSpace;
840
- }
841
-
842
- // Do two passes over the flex items to figure out how to distribute the
843
- // remaining space.
844
- //
845
- // The first pass finds the items whose min/max constraints trigger, freezes
846
- // them at those sizes, and excludes those sizes from the remaining space.
847
- //
848
- // The second pass sets the size of each flexible item. It distributes the
849
- // remaining space amongst the items whose min/max constraints didn't trigger in
850
- // the first pass. For the other items, it sets their sizes by forcing their
851
- // min/max constraints to trigger again.
852
- //
853
- // This two pass approach for resolving min/max constraints deviates from the
854
- // spec. The spec
855
- // (https://www.w3.org/TR/CSS-flexbox-1/#resolve-flexible-lengths) describes a
856
- // process that needs to be repeated a variable number of times. The algorithm
857
- // implemented here won't handle all cases but it was simpler to implement and
858
- // it mitigates performance concerns because we know exactly how many passes
859
- // it'll do.
860
- //
861
- // At the end of this function the child nodes would have the proper size
862
- // assigned to them.
863
- //
864
- static void resolveFlexibleLength(
865
- yoga::Node* const node,
866
- FlexLine& flexLine,
867
- const FlexDirection mainAxis,
868
- const FlexDirection crossAxis,
869
- const Direction direction,
870
- const float mainAxisownerSize,
871
- const float availableInnerMainDim,
872
- const float availableInnerCrossDim,
873
- const float availableInnerWidth,
874
- const float availableInnerHeight,
875
- const bool mainAxisOverflows,
876
- const SizingMode sizingModeCrossDim,
877
- const bool performLayout,
878
- LayoutData& layoutMarkerData,
879
- const uint32_t depth,
880
- const uint32_t generationCount) {
881
- const float originalFreeSpace = flexLine.layout.remainingFreeSpace;
882
- // First pass: detect the flex items whose min/max constraints trigger
883
- distributeFreeSpaceFirstPass(
884
- flexLine,
885
- mainAxis,
886
- mainAxisownerSize,
887
- availableInnerMainDim,
888
- availableInnerWidth);
889
-
890
- // Second pass: resolve the sizes of the flexible items
891
- const float distributedFreeSpace = distributeFreeSpaceSecondPass(
892
- flexLine,
893
- node,
894
- mainAxis,
895
- crossAxis,
896
- direction,
897
- mainAxisownerSize,
898
- availableInnerMainDim,
899
- availableInnerCrossDim,
900
- availableInnerWidth,
901
- availableInnerHeight,
902
- mainAxisOverflows,
903
- sizingModeCrossDim,
904
- performLayout,
905
- layoutMarkerData,
906
- depth,
907
- generationCount);
908
-
909
- flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace;
910
- }
911
-
912
- static void justifyMainAxis(
913
- yoga::Node* const node,
914
- FlexLine& flexLine,
915
- const size_t startOfLineIndex,
916
- const FlexDirection mainAxis,
917
- const FlexDirection crossAxis,
918
- const Direction direction,
919
- const SizingMode sizingModeMainDim,
920
- const SizingMode sizingModeCrossDim,
921
- const float mainAxisownerSize,
922
- const float ownerWidth,
923
- const float availableInnerMainDim,
924
- const float availableInnerCrossDim,
925
- const float availableInnerWidth,
926
- const bool performLayout) {
927
- const auto& style = node->style();
928
-
929
- const float leadingPaddingAndBorderMain =
930
- node->style().computeFlexStartPaddingAndBorder(
931
- mainAxis, direction, ownerWidth);
932
- const float trailingPaddingAndBorderMain =
933
- node->style().computeFlexEndPaddingAndBorder(
934
- mainAxis, direction, ownerWidth);
935
-
936
- const float gap = node->style().computeGapForAxis(mainAxis);
937
- // If we are using "at most" rules in the main axis, make sure that
938
- // remainingFreeSpace is 0 when min main dimension is not given
939
- if (sizingModeMainDim == SizingMode::FitContent &&
940
- flexLine.layout.remainingFreeSpace > 0) {
941
- if (style.minDimension(dimension(mainAxis)).isDefined() &&
942
- style.minDimension(dimension(mainAxis))
943
- .resolve(mainAxisownerSize)
944
- .isDefined()) {
945
- // This condition makes sure that if the size of main dimension(after
946
- // considering child nodes main dim, leading and trailing padding etc)
947
- // falls below min dimension, then the remainingFreeSpace is reassigned
948
- // considering the min dimension
949
-
950
- // `minAvailableMainDim` denotes minimum available space in which child
951
- // can be laid out, it will exclude space consumed by padding and border.
952
- const float minAvailableMainDim = style.minDimension(dimension(mainAxis))
953
- .resolve(mainAxisownerSize)
954
- .unwrap() -
955
- leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
956
- const float occupiedSpaceByChildNodes =
957
- availableInnerMainDim - flexLine.layout.remainingFreeSpace;
958
- flexLine.layout.remainingFreeSpace = yoga::maxOrDefined(
959
- 0.0f, minAvailableMainDim - occupiedSpaceByChildNodes);
960
- } else {
961
- flexLine.layout.remainingFreeSpace = 0;
962
- }
963
- }
964
-
965
- int numberOfAutoMarginsOnCurrentLine = 0;
966
- for (size_t i = startOfLineIndex; i < flexLine.endOfLineIndex; i++) {
967
- auto child = node->getChild(i);
968
- if (child->style().positionType() != PositionType::Absolute) {
969
- if (child->style().flexStartMarginIsAuto(mainAxis, direction)) {
970
- numberOfAutoMarginsOnCurrentLine++;
971
- }
972
- if (child->style().flexEndMarginIsAuto(mainAxis, direction)) {
973
- numberOfAutoMarginsOnCurrentLine++;
974
- }
975
- }
976
- }
977
-
978
- // In order to position the elements in the main axis, we have two controls.
979
- // The space between the beginning and the first element and the space between
980
- // each two elements.
981
- float leadingMainDim = 0;
982
- float betweenMainDim = gap;
983
- const Justify justifyContent = node->style().justifyContent();
984
-
985
- if (numberOfAutoMarginsOnCurrentLine == 0) {
986
- switch (justifyContent) {
987
- case Justify::Center:
988
- leadingMainDim = flexLine.layout.remainingFreeSpace / 2;
989
- break;
990
- case Justify::FlexEnd:
991
- leadingMainDim = flexLine.layout.remainingFreeSpace;
992
- break;
993
- case Justify::SpaceBetween:
994
- if (flexLine.itemsInFlow.size() > 1) {
995
- betweenMainDim +=
996
- yoga::maxOrDefined(flexLine.layout.remainingFreeSpace, 0.0f) /
997
- static_cast<float>(flexLine.itemsInFlow.size() - 1);
998
- }
999
- break;
1000
- case Justify::SpaceEvenly:
1001
- // Space is distributed evenly across all elements
1002
- leadingMainDim = flexLine.layout.remainingFreeSpace /
1003
- static_cast<float>(flexLine.itemsInFlow.size() + 1);
1004
- betweenMainDim += leadingMainDim;
1005
- break;
1006
- case Justify::SpaceAround:
1007
- // Space on the edges is half of the space between elements
1008
- leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace /
1009
- static_cast<float>(flexLine.itemsInFlow.size());
1010
- betweenMainDim += leadingMainDim * 2;
1011
- break;
1012
- case Justify::FlexStart:
1013
- break;
1014
- }
1015
- }
1016
-
1017
- flexLine.layout.mainDim = leadingPaddingAndBorderMain + leadingMainDim;
1018
- flexLine.layout.crossDim = 0;
1019
-
1020
- float maxAscentForCurrentLine = 0;
1021
- float maxDescentForCurrentLine = 0;
1022
- bool isNodeBaselineLayout = isBaselineLayout(node);
1023
- for (size_t i = startOfLineIndex; i < flexLine.endOfLineIndex; i++) {
1024
- const auto child = node->getChild(i);
1025
- const Style& childStyle = child->style();
1026
- const LayoutResults& childLayout = child->getLayout();
1027
- if (childStyle.display() == Display::None) {
1028
- continue;
1029
- }
1030
- if (childStyle.positionType() == PositionType::Absolute &&
1031
- child->style().isFlexStartPositionDefined(mainAxis, direction)) {
1032
- if (performLayout) {
1033
- // In case the child is position absolute and has left/top being
1034
- // defined, we override the position to whatever the user said (and
1035
- // margin/border).
1036
- child->setLayoutPosition(
1037
- child->style().computeFlexStartPosition(
1038
- mainAxis, direction, availableInnerMainDim) +
1039
- node->style().computeFlexStartBorder(mainAxis, direction) +
1040
- child->style().computeFlexStartMargin(
1041
- mainAxis, direction, availableInnerWidth),
1042
- flexStartEdge(mainAxis));
1043
- }
1044
- } else {
1045
- // Now that we placed the element, we need to update the variables.
1046
- // We need to do that only for relative elements. Absolute elements do not
1047
- // take part in that phase.
1048
- if (childStyle.positionType() != PositionType::Absolute) {
1049
- if (child->style().flexStartMarginIsAuto(mainAxis, direction)) {
1050
- flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
1051
- static_cast<float>(numberOfAutoMarginsOnCurrentLine);
1052
- }
1053
-
1054
- if (performLayout) {
1055
- child->setLayoutPosition(
1056
- childLayout.position(flexStartEdge(mainAxis)) +
1057
- flexLine.layout.mainDim,
1058
- flexStartEdge(mainAxis));
1059
- }
1060
-
1061
- if (child != flexLine.itemsInFlow.back()) {
1062
- flexLine.layout.mainDim += betweenMainDim;
1063
- }
1064
-
1065
- if (child->style().flexEndMarginIsAuto(mainAxis, direction)) {
1066
- flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
1067
- static_cast<float>(numberOfAutoMarginsOnCurrentLine);
1068
- }
1069
- bool canSkipFlex =
1070
- !performLayout && sizingModeCrossDim == SizingMode::StretchFit;
1071
- if (canSkipFlex) {
1072
- // If we skipped the flex step, then we can't rely on the measuredDims
1073
- // because they weren't computed. This means we can't call
1074
- // dimensionWithMargin.
1075
- flexLine.layout.mainDim += child->style().computeMarginForAxis(
1076
- mainAxis, availableInnerWidth) +
1077
- childLayout.computedFlexBasis.unwrap();
1078
- flexLine.layout.crossDim = availableInnerCrossDim;
1079
- } else {
1080
- // The main dimension is the sum of all the elements dimension plus
1081
- // the spacing.
1082
- flexLine.layout.mainDim +=
1083
- child->dimensionWithMargin(mainAxis, availableInnerWidth);
1084
-
1085
- if (isNodeBaselineLayout) {
1086
- // If the child is baseline aligned then the cross dimension is
1087
- // calculated by adding maxAscent and maxDescent from the baseline.
1088
- const float ascent = calculateBaseline(child) +
1089
- child->style().computeFlexStartMargin(
1090
- FlexDirection::Column, direction, availableInnerWidth);
1091
- const float descent =
1092
- child->getLayout().measuredDimension(Dimension::Height) +
1093
- child->style().computeMarginForAxis(
1094
- FlexDirection::Column, availableInnerWidth) -
1095
- ascent;
1096
-
1097
- maxAscentForCurrentLine =
1098
- yoga::maxOrDefined(maxAscentForCurrentLine, ascent);
1099
- maxDescentForCurrentLine =
1100
- yoga::maxOrDefined(maxDescentForCurrentLine, descent);
1101
- } else {
1102
- // The cross dimension is the max of the elements dimension since
1103
- // there can only be one element in that cross dimension in the case
1104
- // when the items are not baseline aligned
1105
- flexLine.layout.crossDim = yoga::maxOrDefined(
1106
- flexLine.layout.crossDim,
1107
- child->dimensionWithMargin(crossAxis, availableInnerWidth));
1108
- }
1109
- }
1110
- } else if (performLayout) {
1111
- child->setLayoutPosition(
1112
- childLayout.position(flexStartEdge(mainAxis)) +
1113
- node->style().computeFlexStartBorder(mainAxis, direction) +
1114
- leadingMainDim,
1115
- flexStartEdge(mainAxis));
1116
- }
1117
- }
1118
- }
1119
- flexLine.layout.mainDim += trailingPaddingAndBorderMain;
1120
-
1121
- if (isNodeBaselineLayout) {
1122
- flexLine.layout.crossDim =
1123
- maxAscentForCurrentLine + maxDescentForCurrentLine;
1124
- }
1125
- }
1126
-
1127
- //
1128
- // This is the main routine that implements a subset of the flexbox layout
1129
- // algorithm described in the W3C CSS documentation:
1130
- // https://www.w3.org/TR/CSS3-flexbox/.
1131
- //
1132
- // Limitations of this algorithm, compared to the full standard:
1133
- // * Display property is always assumed to be 'flex' except for Text nodes,
1134
- // which are assumed to be 'inline-flex'.
1135
- // * The 'zIndex' property (or any form of z ordering) is not supported. Nodes
1136
- // are stacked in document order.
1137
- // * The 'order' property is not supported. The order of flex items is always
1138
- // defined by document order.
1139
- // * The 'visibility' property is always assumed to be 'visible'. Values of
1140
- // 'collapse' and 'hidden' are not supported.
1141
- // * There is no support for forced breaks.
1142
- // * It does not support vertical inline directions (top-to-bottom or
1143
- // bottom-to-top text).
1144
- //
1145
- // Deviations from standard:
1146
- // * Section 4.5 of the spec indicates that all flex items have a default
1147
- // minimum main size. For text blocks, for example, this is the width of the
1148
- // widest word. Calculating the minimum width is expensive, so we forego it
1149
- // and assume a default minimum main size of 0.
1150
- // * Min/Max sizes in the main axis are not honored when resolving flexible
1151
- // lengths.
1152
- // * The spec indicates that the default value for 'flexDirection' is 'row',
1153
- // but the algorithm below assumes a default of 'column'.
1154
- //
1155
- // Input parameters:
1156
- // - node: current node to be sized and laid out
1157
- // - availableWidth & availableHeight: available size to be used for sizing
1158
- // the node or YGUndefined if the size is not available; interpretation
1159
- // depends on layout flags
1160
- // - ownerDirection: the inline (text) direction within the owner
1161
- // (left-to-right or right-to-left)
1162
- // - widthSizingMode: indicates the sizing rules for the width (see below
1163
- // for explanation)
1164
- // - heightSizingMode: indicates the sizing rules for the height (see below
1165
- // for explanation)
1166
- // - performLayout: specifies whether the caller is interested in just the
1167
- // dimensions of the node or it requires the entire node and its subtree to
1168
- // be laid out (with final positions)
1169
- //
1170
- // Details:
1171
- // This routine is called recursively to lay out subtrees of flexbox
1172
- // elements. It uses the information in node.style, which is treated as a
1173
- // read-only input. It is responsible for setting the layout.direction and
1174
- // layout.measuredDimensions fields for the input node as well as the
1175
- // layout.position and layout.lineIndex fields for its child nodes. The
1176
- // layout.measuredDimensions field includes any border or padding for the
1177
- // node but does not include margins.
1178
- //
1179
- // When calling calculateLayoutImpl and calculateLayoutInternal, if the
1180
- // caller passes an available size of undefined then it must also pass a
1181
- // measure mode of SizingMode::MaxContent in that dimension.
1182
- //
1183
- static void calculateLayoutImpl(
1184
- yoga::Node* const node,
1185
- const float availableWidth,
1186
- const float availableHeight,
1187
- const Direction ownerDirection,
1188
- const SizingMode widthSizingMode,
1189
- const SizingMode heightSizingMode,
1190
- const float ownerWidth,
1191
- const float ownerHeight,
1192
- const bool performLayout,
1193
- LayoutData& layoutMarkerData,
1194
- const uint32_t depth,
1195
- const uint32_t generationCount,
1196
- const LayoutPassReason reason) {
1197
- yoga::assertFatalWithNode(
1198
- node,
1199
- yoga::isUndefined(availableWidth)
1200
- ? widthSizingMode == SizingMode::MaxContent
1201
- : true,
1202
- "availableWidth is indefinite so widthSizingMode must be "
1203
- "SizingMode::MaxContent");
1204
- yoga::assertFatalWithNode(
1205
- node,
1206
- yoga::isUndefined(availableHeight)
1207
- ? heightSizingMode == SizingMode::MaxContent
1208
- : true,
1209
- "availableHeight is indefinite so heightSizingMode must be "
1210
- "SizingMode::MaxContent");
1211
-
1212
- (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
1213
-
1214
- // Set the resolved resolution in the node's layout.
1215
- const Direction direction = node->resolveDirection(ownerDirection);
1216
- node->setLayoutDirection(direction);
1217
-
1218
- const FlexDirection flexRowDirection =
1219
- resolveDirection(FlexDirection::Row, direction);
1220
- const FlexDirection flexColumnDirection =
1221
- resolveDirection(FlexDirection::Column, direction);
1222
-
1223
- const auto startEdge =
1224
- direction == Direction::LTR ? PhysicalEdge::Left : PhysicalEdge::Right;
1225
- const auto endEdge =
1226
- direction == Direction::LTR ? PhysicalEdge::Right : PhysicalEdge::Left;
1227
-
1228
- const float marginRowLeading = node->style().computeInlineStartMargin(
1229
- flexRowDirection, direction, ownerWidth);
1230
- node->setLayoutMargin(marginRowLeading, startEdge);
1231
- const float marginRowTrailing = node->style().computeInlineEndMargin(
1232
- flexRowDirection, direction, ownerWidth);
1233
- node->setLayoutMargin(marginRowTrailing, endEdge);
1234
- const float marginColumnLeading = node->style().computeInlineStartMargin(
1235
- flexColumnDirection, direction, ownerWidth);
1236
- node->setLayoutMargin(marginColumnLeading, PhysicalEdge::Top);
1237
- const float marginColumnTrailing = node->style().computeInlineEndMargin(
1238
- flexColumnDirection, direction, ownerWidth);
1239
- node->setLayoutMargin(marginColumnTrailing, PhysicalEdge::Bottom);
1240
-
1241
- const float marginAxisRow = marginRowLeading + marginRowTrailing;
1242
- const float marginAxisColumn = marginColumnLeading + marginColumnTrailing;
1243
-
1244
- node->setLayoutBorder(
1245
- node->style().computeInlineStartBorder(flexRowDirection, direction),
1246
- startEdge);
1247
- node->setLayoutBorder(
1248
- node->style().computeInlineEndBorder(flexRowDirection, direction),
1249
- endEdge);
1250
- node->setLayoutBorder(
1251
- node->style().computeInlineStartBorder(flexColumnDirection, direction),
1252
- PhysicalEdge::Top);
1253
- node->setLayoutBorder(
1254
- node->style().computeInlineEndBorder(flexColumnDirection, direction),
1255
- PhysicalEdge::Bottom);
1256
-
1257
- node->setLayoutPadding(
1258
- node->style().computeInlineStartPadding(
1259
- flexRowDirection, direction, ownerWidth),
1260
- startEdge);
1261
- node->setLayoutPadding(
1262
- node->style().computeInlineEndPadding(
1263
- flexRowDirection, direction, ownerWidth),
1264
- endEdge);
1265
- node->setLayoutPadding(
1266
- node->style().computeInlineStartPadding(
1267
- flexColumnDirection, direction, ownerWidth),
1268
- PhysicalEdge::Top);
1269
- node->setLayoutPadding(
1270
- node->style().computeInlineEndPadding(
1271
- flexColumnDirection, direction, ownerWidth),
1272
- PhysicalEdge::Bottom);
1273
-
1274
- if (node->hasMeasureFunc()) {
1275
- measureNodeWithMeasureFunc(
1276
- node,
1277
- availableWidth - marginAxisRow,
1278
- availableHeight - marginAxisColumn,
1279
- widthSizingMode,
1280
- heightSizingMode,
1281
- ownerWidth,
1282
- ownerHeight,
1283
- layoutMarkerData,
1284
- reason);
1285
- return;
1286
- }
1287
-
1288
- const auto childCount = node->getChildCount();
1289
- if (childCount == 0) {
1290
- measureNodeWithoutChildren(
1291
- node,
1292
- availableWidth - marginAxisRow,
1293
- availableHeight - marginAxisColumn,
1294
- widthSizingMode,
1295
- heightSizingMode,
1296
- ownerWidth,
1297
- ownerHeight);
1298
- return;
1299
- }
1300
-
1301
- // If we're not being asked to perform a full layout we can skip the algorithm
1302
- // if we already know the size
1303
- if (!performLayout &&
1304
- measureNodeWithFixedSize(
1305
- node,
1306
- availableWidth - marginAxisRow,
1307
- availableHeight - marginAxisColumn,
1308
- widthSizingMode,
1309
- heightSizingMode,
1310
- ownerWidth,
1311
- ownerHeight)) {
1312
- return;
1313
- }
1314
-
1315
- // At this point we know we're going to perform work. Ensure that each child
1316
- // has a mutable copy.
1317
- node->cloneChildrenIfNeeded();
1318
- // Reset layout flags, as they could have changed.
1319
- node->setLayoutHadOverflow(false);
1320
-
1321
- // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM
1322
- const FlexDirection mainAxis =
1323
- resolveDirection(node->style().flexDirection(), direction);
1324
- const FlexDirection crossAxis = resolveCrossDirection(mainAxis, direction);
1325
- const bool isMainAxisRow = isRow(mainAxis);
1326
- const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap;
1327
-
1328
- const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight;
1329
- const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth;
1330
-
1331
- const float paddingAndBorderAxisMain =
1332
- paddingAndBorderForAxis(node, mainAxis, ownerWidth);
1333
- const float paddingAndBorderAxisCross =
1334
- paddingAndBorderForAxis(node, crossAxis, ownerWidth);
1335
- const float leadingPaddingAndBorderCross =
1336
- node->style().computeFlexStartPaddingAndBorder(
1337
- crossAxis, direction, ownerWidth);
1338
-
1339
- SizingMode sizingModeMainDim =
1340
- isMainAxisRow ? widthSizingMode : heightSizingMode;
1341
- SizingMode sizingModeCrossDim =
1342
- isMainAxisRow ? heightSizingMode : widthSizingMode;
1343
-
1344
- const float paddingAndBorderAxisRow =
1345
- isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross;
1346
- const float paddingAndBorderAxisColumn =
1347
- isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
1348
-
1349
- // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
1350
-
1351
- float availableInnerWidth = calculateAvailableInnerDimension(
1352
- node,
1353
- Dimension::Width,
1354
- availableWidth - marginAxisRow,
1355
- paddingAndBorderAxisRow,
1356
- ownerWidth);
1357
- float availableInnerHeight = calculateAvailableInnerDimension(
1358
- node,
1359
- Dimension::Height,
1360
- availableHeight - marginAxisColumn,
1361
- paddingAndBorderAxisColumn,
1362
- ownerHeight);
1363
-
1364
- float availableInnerMainDim =
1365
- isMainAxisRow ? availableInnerWidth : availableInnerHeight;
1366
- const float availableInnerCrossDim =
1367
- isMainAxisRow ? availableInnerHeight : availableInnerWidth;
1368
-
1369
- // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
1370
-
1371
- // Computed basis + margins + gap
1372
- float totalMainDim = 0;
1373
- totalMainDim += computeFlexBasisForChildren(
1374
- node,
1375
- availableInnerWidth,
1376
- availableInnerHeight,
1377
- widthSizingMode,
1378
- heightSizingMode,
1379
- direction,
1380
- mainAxis,
1381
- performLayout,
1382
- layoutMarkerData,
1383
- depth,
1384
- generationCount);
1385
-
1386
- if (childCount > 1) {
1387
- totalMainDim += node->style().computeGapForAxis(mainAxis) *
1388
- static_cast<float>(childCount - 1);
1389
- }
1390
-
1391
- const bool mainAxisOverflows =
1392
- (sizingModeMainDim != SizingMode::MaxContent) &&
1393
- totalMainDim > availableInnerMainDim;
1394
-
1395
- if (isNodeFlexWrap && mainAxisOverflows &&
1396
- sizingModeMainDim == SizingMode::FitContent) {
1397
- sizingModeMainDim = SizingMode::StretchFit;
1398
- }
1399
- // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
1400
-
1401
- // Indexes of children that represent the first and last items in the line.
1402
- size_t startOfLineIndex = 0;
1403
- size_t endOfLineIndex = 0;
1404
-
1405
- // Number of lines.
1406
- size_t lineCount = 0;
1407
-
1408
- // Accumulated cross dimensions of all lines so far.
1409
- float totalLineCrossDim = 0;
1410
-
1411
- const float crossAxisGap = node->style().computeGapForAxis(crossAxis);
1412
-
1413
- // Max main dimension of all the lines.
1414
- float maxLineMainDim = 0;
1415
- for (; endOfLineIndex < childCount;
1416
- lineCount++, startOfLineIndex = endOfLineIndex) {
1417
- auto flexLine = calculateFlexLine(
1418
- node,
1419
- ownerDirection,
1420
- mainAxisownerSize,
1421
- availableInnerWidth,
1422
- availableInnerMainDim,
1423
- startOfLineIndex,
1424
- lineCount);
1425
-
1426
- endOfLineIndex = flexLine.endOfLineIndex;
1427
-
1428
- // If we don't need to measure the cross axis, we can skip the entire flex
1429
- // step.
1430
- const bool canSkipFlex =
1431
- !performLayout && sizingModeCrossDim == SizingMode::StretchFit;
1432
-
1433
- // STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS
1434
- // Calculate the remaining available space that needs to be allocated. If
1435
- // the main dimension size isn't known, it is computed based on the line
1436
- // length, so there's no more space left to distribute.
1437
-
1438
- bool sizeBasedOnContent = false;
1439
- // If we don't measure with exact main dimension we want to ensure we don't
1440
- // violate min and max
1441
- if (sizingModeMainDim != SizingMode::StretchFit) {
1442
- const auto& style = node->style();
1443
- const float minInnerWidth =
1444
- style.minDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
1445
- paddingAndBorderAxisRow;
1446
- const float maxInnerWidth =
1447
- style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
1448
- paddingAndBorderAxisRow;
1449
- const float minInnerHeight =
1450
- style.minDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
1451
- paddingAndBorderAxisColumn;
1452
- const float maxInnerHeight =
1453
- style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
1454
- paddingAndBorderAxisColumn;
1455
-
1456
- const float minInnerMainDim =
1457
- isMainAxisRow ? minInnerWidth : minInnerHeight;
1458
- const float maxInnerMainDim =
1459
- isMainAxisRow ? maxInnerWidth : maxInnerHeight;
1460
-
1461
- if (yoga::isDefined(minInnerMainDim) &&
1462
- flexLine.sizeConsumed < minInnerMainDim) {
1463
- availableInnerMainDim = minInnerMainDim;
1464
- } else if (
1465
- yoga::isDefined(maxInnerMainDim) &&
1466
- flexLine.sizeConsumed > maxInnerMainDim) {
1467
- availableInnerMainDim = maxInnerMainDim;
1468
- } else {
1469
- bool useLegacyStretchBehaviour =
1470
- node->hasErrata(Errata::StretchFlexBasis);
1471
-
1472
- if (!useLegacyStretchBehaviour &&
1473
- ((yoga::isDefined(flexLine.layout.totalFlexGrowFactors) &&
1474
- flexLine.layout.totalFlexGrowFactors == 0) ||
1475
- (yoga::isDefined(node->resolveFlexGrow()) &&
1476
- node->resolveFlexGrow() == 0))) {
1477
- // If we don't have any children to flex or we can't flex the node
1478
- // itself, space we've used is all space we need. Root node also
1479
- // should be shrunk to minimum
1480
- availableInnerMainDim = flexLine.sizeConsumed;
1481
- }
1482
-
1483
- sizeBasedOnContent = !useLegacyStretchBehaviour;
1484
- }
1485
- }
1486
-
1487
- if (!sizeBasedOnContent && yoga::isDefined(availableInnerMainDim)) {
1488
- flexLine.layout.remainingFreeSpace =
1489
- availableInnerMainDim - flexLine.sizeConsumed;
1490
- } else if (flexLine.sizeConsumed < 0) {
1491
- // availableInnerMainDim is indefinite which means the node is being sized
1492
- // based on its content. sizeConsumed is negative which means
1493
- // the node will allocate 0 points for its content. Consequently,
1494
- // remainingFreeSpace is 0 - sizeConsumed.
1495
- flexLine.layout.remainingFreeSpace = -flexLine.sizeConsumed;
1496
- }
1497
-
1498
- if (!canSkipFlex) {
1499
- resolveFlexibleLength(
1500
- node,
1501
- flexLine,
1502
- mainAxis,
1503
- crossAxis,
1504
- direction,
1505
- mainAxisownerSize,
1506
- availableInnerMainDim,
1507
- availableInnerCrossDim,
1508
- availableInnerWidth,
1509
- availableInnerHeight,
1510
- mainAxisOverflows,
1511
- sizingModeCrossDim,
1512
- performLayout,
1513
- layoutMarkerData,
1514
- depth,
1515
- generationCount);
1516
- }
1517
-
1518
- node->setLayoutHadOverflow(
1519
- node->getLayout().hadOverflow() ||
1520
- (flexLine.layout.remainingFreeSpace < 0));
1521
-
1522
- // STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION
1523
-
1524
- // At this point, all the children have their dimensions set in the main
1525
- // axis. Their dimensions are also set in the cross axis with the exception
1526
- // of items that are aligned "stretch". We need to compute these stretch
1527
- // values and set the final positions.
1528
-
1529
- justifyMainAxis(
1530
- node,
1531
- flexLine,
1532
- startOfLineIndex,
1533
- mainAxis,
1534
- crossAxis,
1535
- direction,
1536
- sizingModeMainDim,
1537
- sizingModeCrossDim,
1538
- mainAxisownerSize,
1539
- ownerWidth,
1540
- availableInnerMainDim,
1541
- availableInnerCrossDim,
1542
- availableInnerWidth,
1543
- performLayout);
1544
-
1545
- float containerCrossAxis = availableInnerCrossDim;
1546
- if (sizingModeCrossDim == SizingMode::MaxContent ||
1547
- sizingModeCrossDim == SizingMode::FitContent) {
1548
- // Compute the cross axis from the max cross dimension of the children.
1549
- containerCrossAxis =
1550
- boundAxis(
1551
- node,
1552
- crossAxis,
1553
- flexLine.layout.crossDim + paddingAndBorderAxisCross,
1554
- crossAxisownerSize,
1555
- ownerWidth) -
1556
- paddingAndBorderAxisCross;
1557
- }
1558
-
1559
- // If there's no flex wrap, the cross dimension is defined by the container.
1560
- if (!isNodeFlexWrap && sizingModeCrossDim == SizingMode::StretchFit) {
1561
- flexLine.layout.crossDim = availableInnerCrossDim;
1562
- }
1563
-
1564
- // As-per https://www.w3.org/TR/css-flexbox-1/#cross-sizing, the
1565
- // cross-size of the line within a single-line container should be bound to
1566
- // min/max constraints before alignment within the line. In a multi-line
1567
- // container, affecting alignment between the lines.
1568
- if (!isNodeFlexWrap) {
1569
- flexLine.layout.crossDim =
1570
- boundAxis(
1571
- node,
1572
- crossAxis,
1573
- flexLine.layout.crossDim + paddingAndBorderAxisCross,
1574
- crossAxisownerSize,
1575
- ownerWidth) -
1576
- paddingAndBorderAxisCross;
1577
- }
1578
-
1579
- // STEP 7: CROSS-AXIS ALIGNMENT
1580
- // We can skip child alignment if we're just measuring the container.
1581
- if (performLayout) {
1582
- for (size_t i = startOfLineIndex; i < endOfLineIndex; i++) {
1583
- const auto child = node->getChild(i);
1584
- if (child->style().display() == Display::None) {
1585
- continue;
1586
- }
1587
- if (child->style().positionType() == PositionType::Absolute) {
1588
- // If the child is absolutely positioned and has a
1589
- // top/left/bottom/right set, override all the previously computed
1590
- // positions to set it correctly.
1591
- const bool isChildLeadingPosDefined =
1592
- child->style().isFlexStartPositionDefined(crossAxis, direction);
1593
- if (isChildLeadingPosDefined) {
1594
- child->setLayoutPosition(
1595
- child->style().computeFlexStartPosition(
1596
- crossAxis, direction, availableInnerCrossDim) +
1597
- node->style().computeFlexStartBorder(crossAxis, direction) +
1598
- child->style().computeFlexStartMargin(
1599
- crossAxis, direction, availableInnerWidth),
1600
- flexStartEdge(crossAxis));
1601
- }
1602
- // If leading position is not defined or calculations result in Nan,
1603
- // default to border + margin
1604
- if (!isChildLeadingPosDefined ||
1605
- yoga::isUndefined(
1606
- child->getLayout().position(flexStartEdge(crossAxis)))) {
1607
- child->setLayoutPosition(
1608
- node->style().computeFlexStartBorder(crossAxis, direction) +
1609
- child->style().computeFlexStartMargin(
1610
- crossAxis, direction, availableInnerWidth),
1611
- flexStartEdge(crossAxis));
1612
- }
1613
- } else {
1614
- float leadingCrossDim = leadingPaddingAndBorderCross;
1615
-
1616
- // For a relative children, we're either using alignItems (owner) or
1617
- // alignSelf (child) in order to determine the position in the cross
1618
- // axis
1619
- const Align alignItem = resolveChildAlignment(node, child);
1620
-
1621
- // If the child uses align stretch, we need to lay it out one more
1622
- // time, this time forcing the cross-axis size to be the computed
1623
- // cross size for the current line.
1624
- if (alignItem == Align::Stretch &&
1625
- !child->style().flexStartMarginIsAuto(crossAxis, direction) &&
1626
- !child->style().flexEndMarginIsAuto(crossAxis, direction)) {
1627
- // If the child defines a definite size for its cross axis, there's
1628
- // no need to stretch.
1629
- if (!child->hasDefiniteLength(
1630
- dimension(crossAxis), availableInnerCrossDim)) {
1631
- float childMainSize =
1632
- child->getLayout().measuredDimension(dimension(mainAxis));
1633
- const auto& childStyle = child->style();
1634
- float childCrossSize = childStyle.aspectRatio().isDefined()
1635
- ? child->style().computeMarginForAxis(
1636
- crossAxis, availableInnerWidth) +
1637
- (isMainAxisRow
1638
- ? childMainSize / childStyle.aspectRatio().unwrap()
1639
- : childMainSize * childStyle.aspectRatio().unwrap())
1640
- : flexLine.layout.crossDim;
1641
-
1642
- childMainSize += child->style().computeMarginForAxis(
1643
- mainAxis, availableInnerWidth);
1644
-
1645
- SizingMode childMainSizingMode = SizingMode::StretchFit;
1646
- SizingMode childCrossSizingMode = SizingMode::StretchFit;
1647
- constrainMaxSizeForMode(
1648
- child,
1649
- mainAxis,
1650
- availableInnerMainDim,
1651
- availableInnerWidth,
1652
- &childMainSizingMode,
1653
- &childMainSize);
1654
- constrainMaxSizeForMode(
1655
- child,
1656
- crossAxis,
1657
- availableInnerCrossDim,
1658
- availableInnerWidth,
1659
- &childCrossSizingMode,
1660
- &childCrossSize);
1661
-
1662
- const float childWidth =
1663
- isMainAxisRow ? childMainSize : childCrossSize;
1664
- const float childHeight =
1665
- !isMainAxisRow ? childMainSize : childCrossSize;
1666
-
1667
- auto alignContent = node->style().alignContent();
1668
- auto crossAxisDoesNotGrow =
1669
- alignContent != Align::Stretch && isNodeFlexWrap;
1670
- const SizingMode childWidthSizingMode =
1671
- yoga::isUndefined(childWidth) ||
1672
- (!isMainAxisRow && crossAxisDoesNotGrow)
1673
- ? SizingMode::MaxContent
1674
- : SizingMode::StretchFit;
1675
- const SizingMode childHeightSizingMode =
1676
- yoga::isUndefined(childHeight) ||
1677
- (isMainAxisRow && crossAxisDoesNotGrow)
1678
- ? SizingMode::MaxContent
1679
- : SizingMode::StretchFit;
1680
-
1681
- calculateLayoutInternal(
1682
- child,
1683
- childWidth,
1684
- childHeight,
1685
- direction,
1686
- childWidthSizingMode,
1687
- childHeightSizingMode,
1688
- availableInnerWidth,
1689
- availableInnerHeight,
1690
- true,
1691
- LayoutPassReason::kStretch,
1692
- layoutMarkerData,
1693
- depth,
1694
- generationCount);
1695
- }
1696
- } else {
1697
- const float remainingCrossDim = containerCrossAxis -
1698
- child->dimensionWithMargin(crossAxis, availableInnerWidth);
1699
-
1700
- if (child->style().flexStartMarginIsAuto(crossAxis, direction) &&
1701
- child->style().flexEndMarginIsAuto(crossAxis, direction)) {
1702
- leadingCrossDim +=
1703
- yoga::maxOrDefined(0.0f, remainingCrossDim / 2);
1704
- } else if (child->style().flexEndMarginIsAuto(
1705
- crossAxis, direction)) {
1706
- // No-Op
1707
- } else if (child->style().flexStartMarginIsAuto(
1708
- crossAxis, direction)) {
1709
- leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim);
1710
- } else if (alignItem == Align::FlexStart) {
1711
- // No-Op
1712
- } else if (alignItem == Align::Center) {
1713
- leadingCrossDim += remainingCrossDim / 2;
1714
- } else {
1715
- leadingCrossDim += remainingCrossDim;
1716
- }
1717
- }
1718
- // And we apply the position
1719
- child->setLayoutPosition(
1720
- child->getLayout().position(flexStartEdge(crossAxis)) +
1721
- totalLineCrossDim + leadingCrossDim,
1722
- flexStartEdge(crossAxis));
1723
- }
1724
- }
1725
- }
1726
-
1727
- const float appliedCrossGap = lineCount != 0 ? crossAxisGap : 0.0f;
1728
- totalLineCrossDim += flexLine.layout.crossDim + appliedCrossGap;
1729
- maxLineMainDim =
1730
- yoga::maxOrDefined(maxLineMainDim, flexLine.layout.mainDim);
1731
- }
1732
-
1733
- // STEP 8: MULTI-LINE CONTENT ALIGNMENT
1734
- // currentLead stores the size of the cross dim
1735
- if (performLayout && (isNodeFlexWrap || isBaselineLayout(node))) {
1736
- float leadPerLine = 0;
1737
- float currentLead = leadingPaddingAndBorderCross;
1738
-
1739
- const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
1740
- ? availableInnerCrossDim + paddingAndBorderAxisCross
1741
- : node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize)
1742
- ? node->getResolvedDimension(dimension(crossAxis))
1743
- .resolve(crossAxisownerSize)
1744
- .unwrap()
1745
- : totalLineCrossDim + paddingAndBorderAxisCross;
1746
-
1747
- const float innerCrossDim =
1748
- boundAxis(node, crossAxis, unclampedCrossDim, ownerHeight, ownerWidth) -
1749
- paddingAndBorderAxisCross;
1750
-
1751
- const float remainingAlignContentDim = innerCrossDim - totalLineCrossDim;
1752
- switch (node->style().alignContent()) {
1753
- case Align::FlexEnd:
1754
- currentLead += remainingAlignContentDim;
1755
- break;
1756
- case Align::Center:
1757
- currentLead += remainingAlignContentDim / 2;
1758
- break;
1759
- case Align::Stretch:
1760
- if (innerCrossDim > totalLineCrossDim) {
1761
- leadPerLine =
1762
- remainingAlignContentDim / static_cast<float>(lineCount);
1763
- }
1764
- break;
1765
- case Align::SpaceAround:
1766
- if (innerCrossDim > totalLineCrossDim) {
1767
- currentLead +=
1768
- remainingAlignContentDim / (2 * static_cast<float>(lineCount));
1769
- leadPerLine =
1770
- remainingAlignContentDim / static_cast<float>(lineCount);
1771
- } else {
1772
- currentLead += remainingAlignContentDim / 2;
1773
- }
1774
- break;
1775
- case Align::SpaceEvenly:
1776
- if (innerCrossDim > totalLineCrossDim) {
1777
- currentLead +=
1778
- remainingAlignContentDim / static_cast<float>(lineCount + 1);
1779
- leadPerLine =
1780
- remainingAlignContentDim / static_cast<float>(lineCount + 1);
1781
- } else {
1782
- currentLead += remainingAlignContentDim / 2;
1783
- }
1784
- break;
1785
- case Align::SpaceBetween:
1786
- if (innerCrossDim > totalLineCrossDim && lineCount > 1) {
1787
- leadPerLine =
1788
- remainingAlignContentDim / static_cast<float>(lineCount - 1);
1789
- }
1790
- break;
1791
- case Align::Auto:
1792
- case Align::FlexStart:
1793
- case Align::Baseline:
1794
- break;
1795
- }
1796
- size_t endIndex = 0;
1797
- for (size_t i = 0; i < lineCount; i++) {
1798
- const size_t startIndex = endIndex;
1799
- size_t ii;
1800
-
1801
- // compute the line's height and find the endIndex
1802
- float lineHeight = 0;
1803
- float maxAscentForCurrentLine = 0;
1804
- float maxDescentForCurrentLine = 0;
1805
- for (ii = startIndex; ii < childCount; ii++) {
1806
- const auto child = node->getChild(ii);
1807
- if (child->style().display() == Display::None) {
1808
- continue;
1809
- }
1810
- if (child->style().positionType() != PositionType::Absolute) {
1811
- if (child->getLineIndex() != i) {
1812
- break;
1813
- }
1814
- if (child->isLayoutDimensionDefined(crossAxis)) {
1815
- lineHeight = yoga::maxOrDefined(
1816
- lineHeight,
1817
- child->getLayout().measuredDimension(dimension(crossAxis)) +
1818
- child->style().computeMarginForAxis(
1819
- crossAxis, availableInnerWidth));
1820
- }
1821
- if (resolveChildAlignment(node, child) == Align::Baseline) {
1822
- const float ascent = calculateBaseline(child) +
1823
- child->style().computeFlexStartMargin(
1824
- FlexDirection::Column, direction, availableInnerWidth);
1825
- const float descent =
1826
- child->getLayout().measuredDimension(Dimension::Height) +
1827
- child->style().computeMarginForAxis(
1828
- FlexDirection::Column, availableInnerWidth) -
1829
- ascent;
1830
- maxAscentForCurrentLine =
1831
- yoga::maxOrDefined(maxAscentForCurrentLine, ascent);
1832
- maxDescentForCurrentLine =
1833
- yoga::maxOrDefined(maxDescentForCurrentLine, descent);
1834
- lineHeight = yoga::maxOrDefined(
1835
- lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine);
1836
- }
1837
- }
1838
- }
1839
- endIndex = ii;
1840
- currentLead += i != 0 ? crossAxisGap : 0;
1841
-
1842
- if (performLayout) {
1843
- for (ii = startIndex; ii < endIndex; ii++) {
1844
- const auto child = node->getChild(ii);
1845
- if (child->style().display() == Display::None) {
1846
- continue;
1847
- }
1848
- if (child->style().positionType() != PositionType::Absolute) {
1849
- switch (resolveChildAlignment(node, child)) {
1850
- case Align::FlexStart: {
1851
- child->setLayoutPosition(
1852
- currentLead +
1853
- child->style().computeFlexStartPosition(
1854
- crossAxis, direction, availableInnerWidth),
1855
- flexStartEdge(crossAxis));
1856
- break;
1857
- }
1858
- case Align::FlexEnd: {
1859
- child->setLayoutPosition(
1860
- currentLead + lineHeight -
1861
- child->style().computeFlexEndMargin(
1862
- crossAxis, direction, availableInnerWidth) -
1863
- child->getLayout().measuredDimension(
1864
- dimension(crossAxis)),
1865
- flexStartEdge(crossAxis));
1866
- break;
1867
- }
1868
- case Align::Center: {
1869
- float childHeight =
1870
- child->getLayout().measuredDimension(dimension(crossAxis));
1871
-
1872
- child->setLayoutPosition(
1873
- currentLead + (lineHeight - childHeight) / 2,
1874
- flexStartEdge(crossAxis));
1875
- break;
1876
- }
1877
- case Align::Stretch: {
1878
- child->setLayoutPosition(
1879
- currentLead +
1880
- child->style().computeFlexStartMargin(
1881
- crossAxis, direction, availableInnerWidth),
1882
- flexStartEdge(crossAxis));
1883
-
1884
- // Remeasure child with the line height as it as been only
1885
- // measured with the owners height yet.
1886
- if (!child->hasDefiniteLength(
1887
- dimension(crossAxis), availableInnerCrossDim)) {
1888
- const float childWidth = isMainAxisRow
1889
- ? (child->getLayout().measuredDimension(
1890
- Dimension::Width) +
1891
- child->style().computeMarginForAxis(
1892
- mainAxis, availableInnerWidth))
1893
- : leadPerLine + lineHeight;
1894
-
1895
- const float childHeight = !isMainAxisRow
1896
- ? (child->getLayout().measuredDimension(
1897
- Dimension::Height) +
1898
- child->style().computeMarginForAxis(
1899
- crossAxis, availableInnerWidth))
1900
- : leadPerLine + lineHeight;
1901
-
1902
- if (!(yoga::inexactEquals(
1903
- childWidth,
1904
- child->getLayout().measuredDimension(
1905
- Dimension::Width)) &&
1906
- yoga::inexactEquals(
1907
- childHeight,
1908
- child->getLayout().measuredDimension(
1909
- Dimension::Height)))) {
1910
- calculateLayoutInternal(
1911
- child,
1912
- childWidth,
1913
- childHeight,
1914
- direction,
1915
- SizingMode::StretchFit,
1916
- SizingMode::StretchFit,
1917
- availableInnerWidth,
1918
- availableInnerHeight,
1919
- true,
1920
- LayoutPassReason::kMultilineStretch,
1921
- layoutMarkerData,
1922
- depth,
1923
- generationCount);
1924
- }
1925
- }
1926
- break;
1927
- }
1928
- case Align::Baseline: {
1929
- child->setLayoutPosition(
1930
- currentLead + maxAscentForCurrentLine -
1931
- calculateBaseline(child) +
1932
- child->style().computeFlexStartPosition(
1933
- FlexDirection::Column,
1934
- direction,
1935
- availableInnerCrossDim),
1936
- PhysicalEdge::Top);
1937
-
1938
- break;
1939
- }
1940
- case Align::Auto:
1941
- case Align::SpaceBetween:
1942
- case Align::SpaceAround:
1943
- case Align::SpaceEvenly:
1944
- break;
1945
- }
1946
- }
1947
- }
1948
- }
1949
- currentLead = currentLead + leadPerLine + lineHeight;
1950
- }
1951
- }
1952
-
1953
- // STEP 9: COMPUTING FINAL DIMENSIONS
1954
-
1955
- node->setLayoutMeasuredDimension(
1956
- boundAxis(
1957
- node,
1958
- FlexDirection::Row,
1959
- availableWidth - marginAxisRow,
1960
- ownerWidth,
1961
- ownerWidth),
1962
- Dimension::Width);
1963
-
1964
- node->setLayoutMeasuredDimension(
1965
- boundAxis(
1966
- node,
1967
- FlexDirection::Column,
1968
- availableHeight - marginAxisColumn,
1969
- ownerHeight,
1970
- ownerWidth),
1971
- Dimension::Height);
1972
-
1973
- // If the user didn't specify a width or height for the node, set the
1974
- // dimensions based on the children.
1975
- if (sizingModeMainDim == SizingMode::MaxContent ||
1976
- (node->style().overflow() != Overflow::Scroll &&
1977
- sizingModeMainDim == SizingMode::FitContent)) {
1978
- // Clamp the size to the min/max size, if specified, and make sure it
1979
- // doesn't go below the padding and border amount.
1980
- node->setLayoutMeasuredDimension(
1981
- boundAxis(
1982
- node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth),
1983
- dimension(mainAxis));
1984
-
1985
- } else if (
1986
- sizingModeMainDim == SizingMode::FitContent &&
1987
- node->style().overflow() == Overflow::Scroll) {
1988
- node->setLayoutMeasuredDimension(
1989
- yoga::maxOrDefined(
1990
- yoga::minOrDefined(
1991
- availableInnerMainDim + paddingAndBorderAxisMain,
1992
- boundAxisWithinMinAndMax(
1993
- node,
1994
- mainAxis,
1995
- FloatOptional{maxLineMainDim},
1996
- mainAxisownerSize)
1997
- .unwrap()),
1998
- paddingAndBorderAxisMain),
1999
- dimension(mainAxis));
2000
- }
2001
-
2002
- if (sizingModeCrossDim == SizingMode::MaxContent ||
2003
- (node->style().overflow() != Overflow::Scroll &&
2004
- sizingModeCrossDim == SizingMode::FitContent)) {
2005
- // Clamp the size to the min/max size, if specified, and make sure it
2006
- // doesn't go below the padding and border amount.
2007
- node->setLayoutMeasuredDimension(
2008
- boundAxis(
2009
- node,
2010
- crossAxis,
2011
- totalLineCrossDim + paddingAndBorderAxisCross,
2012
- crossAxisownerSize,
2013
- ownerWidth),
2014
- dimension(crossAxis));
2015
-
2016
- } else if (
2017
- sizingModeCrossDim == SizingMode::FitContent &&
2018
- node->style().overflow() == Overflow::Scroll) {
2019
- node->setLayoutMeasuredDimension(
2020
- yoga::maxOrDefined(
2021
- yoga::minOrDefined(
2022
- availableInnerCrossDim + paddingAndBorderAxisCross,
2023
- boundAxisWithinMinAndMax(
2024
- node,
2025
- crossAxis,
2026
- FloatOptional{
2027
- totalLineCrossDim + paddingAndBorderAxisCross},
2028
- crossAxisownerSize)
2029
- .unwrap()),
2030
- paddingAndBorderAxisCross),
2031
- dimension(crossAxis));
2032
- }
2033
-
2034
- // As we only wrapped in normal direction yet, we need to reverse the
2035
- // positions on wrap-reverse.
2036
- if (performLayout && node->style().flexWrap() == Wrap::WrapReverse) {
2037
- for (size_t i = 0; i < childCount; i++) {
2038
- const auto child = node->getChild(i);
2039
- if (child->style().positionType() != PositionType::Absolute) {
2040
- child->setLayoutPosition(
2041
- node->getLayout().measuredDimension(dimension(crossAxis)) -
2042
- child->getLayout().position(flexStartEdge(crossAxis)) -
2043
- child->getLayout().measuredDimension(dimension(crossAxis)),
2044
- flexStartEdge(crossAxis));
2045
- }
2046
- }
2047
- }
2048
-
2049
- if (performLayout) {
2050
- // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
2051
- // Let the containing block layout its absolute descendants. By definition
2052
- // the containing block will not be static unless we are at the root.
2053
- if (node->style().positionType() != PositionType::Static ||
2054
- node->alwaysFormsContainingBlock() || depth == 1) {
2055
- layoutAbsoluteDescendants(
2056
- node,
2057
- node,
2058
- isMainAxisRow ? sizingModeMainDim : sizingModeCrossDim,
2059
- direction,
2060
- layoutMarkerData,
2061
- depth,
2062
- generationCount,
2063
- 0.0f,
2064
- 0.0f,
2065
- availableInnerWidth,
2066
- availableInnerHeight);
2067
- }
2068
-
2069
- // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN
2070
- const bool needsMainTrailingPos = needsTrailingPosition(mainAxis);
2071
- const bool needsCrossTrailingPos = needsTrailingPosition(crossAxis);
2072
-
2073
- if (needsMainTrailingPos || needsCrossTrailingPos) {
2074
- for (size_t i = 0; i < childCount; i++) {
2075
- const auto child = node->getChild(i);
2076
- // Absolute children will be handled by their containing block since we
2077
- // cannot guarantee that their positions are set when their parents are
2078
- // done with layout.
2079
- if (child->style().display() == Display::None ||
2080
- child->style().positionType() == PositionType::Absolute) {
2081
- continue;
2082
- }
2083
- if (needsMainTrailingPos) {
2084
- setChildTrailingPosition(node, child, mainAxis);
2085
- }
2086
-
2087
- if (needsCrossTrailingPos) {
2088
- setChildTrailingPosition(node, child, crossAxis);
2089
- }
2090
- }
2091
- }
2092
- }
2093
- }
2094
-
2095
- //
2096
- // This is a wrapper around the calculateLayoutImpl function. It determines
2097
- // whether the layout request is redundant and can be skipped.
2098
- //
2099
- // Parameters:
2100
- // Input parameters are the same as calculateLayoutImpl (see above)
2101
- // Return parameter is true if layout was performed, false if skipped
2102
- //
2103
- bool calculateLayoutInternal(
2104
- yoga::Node* const node,
2105
- const float availableWidth,
2106
- const float availableHeight,
2107
- const Direction ownerDirection,
2108
- const SizingMode widthSizingMode,
2109
- const SizingMode heightSizingMode,
2110
- const float ownerWidth,
2111
- const float ownerHeight,
2112
- const bool performLayout,
2113
- const LayoutPassReason reason,
2114
- LayoutData& layoutMarkerData,
2115
- uint32_t depth,
2116
- const uint32_t generationCount) {
2117
- LayoutResults* layout = &node->getLayout();
2118
-
2119
- depth++;
2120
-
2121
- const bool needToVisitNode =
2122
- (node->isDirty() && layout->generationCount != generationCount) ||
2123
- layout->configVersion != node->getConfig()->getVersion() || // [Windows]
2124
- layout->lastOwnerDirection != ownerDirection;
2125
-
2126
- if (needToVisitNode) {
2127
- // Invalidate the cached results.
2128
- layout->nextCachedMeasurementsIndex = 0;
2129
- layout->cachedLayout.availableWidth = -1;
2130
- layout->cachedLayout.availableHeight = -1;
2131
- layout->cachedLayout.widthSizingMode = SizingMode::MaxContent;
2132
- layout->cachedLayout.heightSizingMode = SizingMode::MaxContent;
2133
- layout->cachedLayout.computedWidth = -1;
2134
- layout->cachedLayout.computedHeight = -1;
2135
- }
2136
-
2137
- CachedMeasurement* cachedResults = nullptr;
2138
-
2139
- // Determine whether the results are already cached. We maintain a separate
2140
- // cache for layouts and measurements. A layout operation modifies the
2141
- // positions and dimensions for nodes in the subtree. The algorithm assumes
2142
- // that each node gets laid out a maximum of one time per tree layout, but
2143
- // multiple measurements may be required to resolve all of the flex
2144
- // dimensions. We handle nodes with measure functions specially here because
2145
- // they are the most expensive to measure, so it's worth avoiding redundant
2146
- // measurements if at all possible.
2147
- if (node->hasMeasureFunc()) {
2148
- const float marginAxisRow =
2149
- node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth);
2150
- const float marginAxisColumn =
2151
- node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
2152
-
2153
- // First, try to use the layout cache.
2154
- if (canUseCachedMeasurement(
2155
- widthSizingMode,
2156
- availableWidth,
2157
- heightSizingMode,
2158
- availableHeight,
2159
- layout->cachedLayout.widthSizingMode,
2160
- layout->cachedLayout.availableWidth,
2161
- layout->cachedLayout.heightSizingMode,
2162
- layout->cachedLayout.availableHeight,
2163
- layout->cachedLayout.computedWidth,
2164
- layout->cachedLayout.computedHeight,
2165
- marginAxisRow,
2166
- marginAxisColumn,
2167
- node->getConfig())) {
2168
- cachedResults = &layout->cachedLayout;
2169
- } else {
2170
- // Try to use the measurement cache.
2171
- for (size_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
2172
- if (canUseCachedMeasurement(
2173
- widthSizingMode,
2174
- availableWidth,
2175
- heightSizingMode,
2176
- availableHeight,
2177
- layout->cachedMeasurements[i].widthSizingMode,
2178
- layout->cachedMeasurements[i].availableWidth,
2179
- layout->cachedMeasurements[i].heightSizingMode,
2180
- layout->cachedMeasurements[i].availableHeight,
2181
- layout->cachedMeasurements[i].computedWidth,
2182
- layout->cachedMeasurements[i].computedHeight,
2183
- marginAxisRow,
2184
- marginAxisColumn,
2185
- node->getConfig())) {
2186
- cachedResults = &layout->cachedMeasurements[i];
2187
- break;
2188
- }
2189
- }
2190
- }
2191
- } else if (performLayout) {
2192
- if (yoga::inexactEquals(
2193
- layout->cachedLayout.availableWidth, availableWidth) &&
2194
- yoga::inexactEquals(
2195
- layout->cachedLayout.availableHeight, availableHeight) &&
2196
- layout->cachedLayout.widthSizingMode == widthSizingMode &&
2197
- layout->cachedLayout.heightSizingMode == heightSizingMode) {
2198
- cachedResults = &layout->cachedLayout;
2199
- }
2200
- } else {
2201
- for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
2202
- if (yoga::inexactEquals(
2203
- layout->cachedMeasurements[i].availableWidth, availableWidth) &&
2204
- yoga::inexactEquals(
2205
- layout->cachedMeasurements[i].availableHeight, availableHeight) &&
2206
- layout->cachedMeasurements[i].widthSizingMode == widthSizingMode &&
2207
- layout->cachedMeasurements[i].heightSizingMode == heightSizingMode) {
2208
- cachedResults = &layout->cachedMeasurements[i];
2209
- break;
2210
- }
2211
- }
2212
- }
2213
-
2214
- if (!needToVisitNode && cachedResults != nullptr) {
2215
- layout->setMeasuredDimension(
2216
- Dimension::Width, cachedResults->computedWidth);
2217
- layout->setMeasuredDimension(
2218
- Dimension::Height, cachedResults->computedHeight);
2219
-
2220
- (performLayout ? layoutMarkerData.cachedLayouts
2221
- : layoutMarkerData.cachedMeasures) += 1;
2222
- } else {
2223
- calculateLayoutImpl(
2224
- node,
2225
- availableWidth,
2226
- availableHeight,
2227
- ownerDirection,
2228
- widthSizingMode,
2229
- heightSizingMode,
2230
- ownerWidth,
2231
- ownerHeight,
2232
- performLayout,
2233
- layoutMarkerData,
2234
- depth,
2235
- generationCount,
2236
- reason);
2237
-
2238
- layout->lastOwnerDirection = ownerDirection;
2239
- layout->configVersion = node->getConfig()->getVersion(); // [Windows]
2240
-
2241
- if (cachedResults == nullptr) {
2242
- layoutMarkerData.maxMeasureCache = std::max(
2243
- layoutMarkerData.maxMeasureCache,
2244
- layout->nextCachedMeasurementsIndex + 1u);
2245
-
2246
- if (layout->nextCachedMeasurementsIndex ==
2247
- LayoutResults::MaxCachedMeasurements) {
2248
- layout->nextCachedMeasurementsIndex = 0;
2249
- }
2250
-
2251
- CachedMeasurement* newCacheEntry;
2252
- if (performLayout) {
2253
- // Use the single layout cache entry.
2254
- newCacheEntry = &layout->cachedLayout;
2255
- } else {
2256
- // Allocate a new measurement cache entry.
2257
- newCacheEntry =
2258
- &layout->cachedMeasurements[layout->nextCachedMeasurementsIndex];
2259
- layout->nextCachedMeasurementsIndex++;
2260
- }
2261
-
2262
- newCacheEntry->availableWidth = availableWidth;
2263
- newCacheEntry->availableHeight = availableHeight;
2264
- newCacheEntry->widthSizingMode = widthSizingMode;
2265
- newCacheEntry->heightSizingMode = heightSizingMode;
2266
- newCacheEntry->computedWidth =
2267
- layout->measuredDimension(Dimension::Width);
2268
- newCacheEntry->computedHeight =
2269
- layout->measuredDimension(Dimension::Height);
2270
- }
2271
- }
2272
-
2273
- if (performLayout) {
2274
- node->setLayoutDimension(
2275
- node->getLayout().measuredDimension(Dimension::Width),
2276
- Dimension::Width);
2277
- node->setLayoutDimension(
2278
- node->getLayout().measuredDimension(Dimension::Height),
2279
- Dimension::Height);
2280
-
2281
- node->setHasNewLayout(true);
2282
- node->setDirty(false);
2283
- }
2284
-
2285
- layout->generationCount = generationCount;
2286
-
2287
- LayoutType layoutType;
2288
- if (performLayout) {
2289
- layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout
2290
- ? LayoutType::kCachedLayout
2291
- : LayoutType::kLayout;
2292
- } else {
2293
- layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure
2294
- : LayoutType::kMeasure;
2295
- }
2296
- Event::publish<Event::NodeLayout>(node, {layoutType});
2297
-
2298
- return (needToVisitNode || cachedResults == nullptr);
2299
- }
2300
-
2301
- void calculateLayout(
2302
- yoga::Node* const node,
2303
- const float ownerWidth,
2304
- const float ownerHeight,
2305
- const Direction ownerDirection) {
2306
- Event::publish<Event::LayoutPassStart>(node);
2307
- LayoutData markerData = {};
2308
-
2309
- // Increment the generation count. This will force the recursive routine to
2310
- // visit all dirty nodes at least once. Subsequent visits will be skipped if
2311
- // the input parameters don't change.
2312
- gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
2313
- node->resolveDimension();
2314
- float width = YGUndefined;
2315
- SizingMode widthSizingMode = SizingMode::MaxContent;
2316
- const auto& style = node->style();
2317
- if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
2318
- width =
2319
- (node->getResolvedDimension(dimension(FlexDirection::Row))
2320
- .resolve(ownerWidth)
2321
- .unwrap() +
2322
- node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth));
2323
- widthSizingMode = SizingMode::StretchFit;
2324
- } else if (style.maxDimension(Dimension::Width)
2325
- .resolve(ownerWidth)
2326
- .isDefined()) {
2327
- width = style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap();
2328
- widthSizingMode = SizingMode::FitContent;
2329
- } else {
2330
- width = ownerWidth;
2331
- widthSizingMode = yoga::isUndefined(width) ? SizingMode::MaxContent
2332
- : SizingMode::StretchFit;
2333
- }
2334
-
2335
- float height = YGUndefined;
2336
- SizingMode heightSizingMode = SizingMode::MaxContent;
2337
- if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
2338
- height =
2339
- (node->getResolvedDimension(dimension(FlexDirection::Column))
2340
- .resolve(ownerHeight)
2341
- .unwrap() +
2342
- node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth));
2343
- heightSizingMode = SizingMode::StretchFit;
2344
- } else if (style.maxDimension(Dimension::Height)
2345
- .resolve(ownerHeight)
2346
- .isDefined()) {
2347
- height =
2348
- style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap();
2349
- heightSizingMode = SizingMode::FitContent;
2350
- } else {
2351
- height = ownerHeight;
2352
- heightSizingMode = yoga::isUndefined(height) ? SizingMode::MaxContent
2353
- : SizingMode::StretchFit;
2354
- }
2355
- if (calculateLayoutInternal(
2356
- node,
2357
- width,
2358
- height,
2359
- ownerDirection,
2360
- widthSizingMode,
2361
- heightSizingMode,
2362
- ownerWidth,
2363
- ownerHeight,
2364
- true,
2365
- LayoutPassReason::kInitial,
2366
- markerData,
2367
- 0, // tree root
2368
- gCurrentGenerationCount.load(std::memory_order_relaxed))) {
2369
- node->setPosition(
2370
- node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth);
2371
- roundLayoutResultsToPixelGrid(node, 0.0f, 0.0f);
2372
- }
2373
-
2374
- Event::publish<Event::LayoutPassEnd>(node, {&markerData});
2375
- }
2376
-
2377
- } // namespace facebook::yoga