react-native-windows 0.75.4 → 0.76.0-preview.1

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