-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Changes two important aspects of `StyleSheet.compose`: - Extract it from `StyleSheet` so that it can be imported from other internal modules without incurring circular dependencies. (Surprisingly, `StyleSheet` has a lot of dependencies.) - Avoid a redundant `style1 != null` check. Changelog: [General][Changed] - Optimized performance of `StyleSheet.compose` Reviewed By: sammy-SC Differential Revision: D56621407
- Loading branch information
1 parent
be06fd4
commit cbfcf25
Showing
2 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/react-native/Libraries/StyleSheet/composeStyles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
/** | ||
* Combines two styles such that `style2` will override any styles in `style1`. | ||
* If either style is null or undefined, the other one is returned without | ||
* allocating an array, saving allocations and enabling memoization. | ||
*/ | ||
export default function composeStyles<T1, T2>( | ||
style1: ?T1, | ||
style2: ?T2, | ||
): ?(T1 | T2 | $ReadOnlyArray<T1 | T2>) { | ||
if (style2 == null) { | ||
return style1; | ||
} | ||
if (style1 == null) { | ||
return style2; | ||
} | ||
return [style1, style2]; | ||
} |