Skip to content

Commit d63ba47

Browse files
astreetFacebook Github Bot
authored andcommitted
BREAKING [react_native] Move to new C-based implementation of css-layout in RN Android
Summary: Moves from CSSNodeDEPRECATED to CSSNode. This has shown to be a huge performance win for layout time within FB. This is BREAKING because CSSNode contains bug fixes that were not migrated to CSSNodeDEPRECATED which may change the way your layout appears. The most common of these by far involves `flex: 1`. Previously, developers had to put `flex: 1` in many places it didn't belong in order to work around a bug in css-layout. Now `flex: 1` is treated properly and, unfortunately, this means that your layout may no longer look correct. Specifically, you may see that your layout looks collapsed, or children don't render. The fix is to simply remove `flex: 1` from those containers. Reviewed By: emilsjolander Differential Revision: D3992787 fbshipit-source-id: 7a3a2a34a8941c0524e6ba3c5379e434d3e03247
1 parent 27817be commit d63ba47

16 files changed

Lines changed: 124 additions & 33 deletions

File tree

‎ReactAndroid/DEFS‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# - At Facebook by running buck from the root of the fb repo
55
# - Outside of Facebook by running buck in the root of the git repo
66

7+
IS_OSS_BUILD = True
8+
79
with allow_unsafe_import():
810
import os
911

@@ -35,6 +37,8 @@ JSC_DEPS = [
3537

3638
CSSLAYOUT_TARGET = '//ReactAndroid/src/main/java/com/facebook:csslayout'
3739
FBGLOGINIT_TARGET = '//ReactAndroid/src/main/jni/first-party/fbgloginit:fbgloginit'
40+
FBJNI_TARGET = '//ReactAndroid/src/main/jni/first-party/fb:jni'
41+
JNI_TARGET = '//ReactAndroid/src/main/jni/first-party/jni-hack:jni-hack'
3842

3943
# React property preprocessor
4044
original_android_library=android_library
@@ -76,9 +80,7 @@ def android_library(
7680
*args,
7781
**kwargs)
7882

79-
80-
def robolectric3_test(name, deps, vm_args=None, *args, **kwargs):
81-
83+
def rn_robolectric_test(name, srcs, vm_args = None, *args, **kwargs):
8284
vm_args = vm_args or []
8385

8486
# We may need to create buck-out/gen/ if we're running after buck clean.
@@ -100,11 +102,16 @@ def robolectric3_test(name, deps, vm_args=None, *args, **kwargs):
100102
'-Djava.io.tmpdir=%s' % os.path.join(os.path.abspath('.'),
101103
'buck-out/bin'))
102104

103-
# defined in BUCK
105+
# RN tests use Powermock, which means they get their own ClassLoaders.
106+
# Because the csslayout native library (or any native library) can only be loaded into one
107+
# ClassLoader at a time, we need to run each in its own process, hence fork_mode = 'per_test'.
104108
robolectric_test(
105-
name=name,
106-
deps=deps,
107-
vm_args=vm_args + extra_vm_args,
108-
*args,
109-
**kwargs
110-
)
109+
name = name,
110+
use_cxx_libraries = True,
111+
cxx_library_whitelist = [
112+
'//ReactAndroid/src/main/jni/first-party/csslayoutjni:jni',
113+
],
114+
fork_mode = 'per_test',
115+
srcs = srcs,
116+
vm_args = vm_args + extra_vm_args,
117+
*args, **kwargs)

‎ReactAndroid/src/androidTest/js/UIManagerTestModule.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ var CenteredTextView = React.createClass({
119119
width: 200,
120120
height: 100,
121121
backgroundColor: '#aa3311',
122-
flex: 1,
123122
justifyContent: 'center',
124123
alignItems: 'center',
125124
},

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.facebook.csslayout.CSSFlexDirection;
2020
import com.facebook.csslayout.CSSJustify;
2121
import com.facebook.csslayout.CSSLayoutContext;
22+
import com.facebook.csslayout.CSSNode;
2223
import com.facebook.csslayout.CSSNodeAPI;
23-
import com.facebook.csslayout.CSSNodeDEPRECATED;
2424
import com.facebook.csslayout.CSSOverflow;
2525
import com.facebook.csslayout.CSSPositionType;
2626
import com.facebook.csslayout.CSSWrap;
@@ -30,9 +30,9 @@
3030

3131
/**
3232
* Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily
33-
* for layouting therefore it extends {@link CSSNodeDEPRECATED} to allow that. They also help with handling
34-
* Common base subclass of {@link CSSNodeDEPRECATED} for all layout nodes for react-based view. It extends
35-
* {@link CSSNodeDEPRECATED} by adding additional capabilities.
33+
* for layouting therefore it extends {@link CSSNode} to allow that. They also help with handling
34+
* Common base subclass of {@link CSSNode} for all layout nodes for react-based view. It extends
35+
* {@link CSSNode} by adding additional capabilities.
3636
*
3737
* Instances of this class receive property updates from JS via @{link UIManagerModule}. Subclasses
3838
* may use {@link #updateShadowNode} to persist some of the updated fields in the node instance that
@@ -74,7 +74,7 @@ public class ReactShadowNode {
7474
private float mAbsoluteBottom;
7575
private final Spacing mDefaultPadding = new Spacing(0);
7676
private final Spacing mPadding = new Spacing(CSSConstants.UNDEFINED);
77-
private final CSSNodeDEPRECATED mCSSNode = new CSSNodeDEPRECATED();
77+
private final CSSNode mCSSNode = new CSSNode();
7878

7979
/**
8080
* Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not

‎ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextInlineImageShadowNode.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
package com.facebook.react.views.text;
1111

12-
import com.facebook.csslayout.CSSNodeDEPRECATED;
12+
import com.facebook.csslayout.CSSNode;
1313
import com.facebook.react.uimanager.LayoutShadowNode;
1414

1515
/**
16-
* Base class for {@link CSSNodeDEPRECATED}s that represent inline images.
16+
* Base class for {@link CSSNode}s that represent inline images.
1717
*/
1818
public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode {
1919

@@ -22,5 +22,4 @@ public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode {
2222
* place of this node.
2323
*/
2424
public abstract TextInlineImageSpan buildInlineImageSpan();
25-
2625
}

‎ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import android.net.Uri;
1919

2020
import com.facebook.common.util.UriUtil;
21-
import com.facebook.csslayout.CSSNodeDEPRECATED;
2221
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
2322
import com.facebook.react.bridge.ReadableArray;
2423
import com.facebook.react.uimanager.annotations.ReactProp;
2524
import com.facebook.react.views.text.ReactTextInlineImageShadowNode;
2625
import com.facebook.react.views.text.TextInlineImageSpan;
2726

2827
/**
29-
* {@link CSSNodeDEPRECATED} that represents an inline image. Loading is done using Fresco.
28+
* Shadow node that represents an inline image. Loading is done using Fresco.
3029
*
3130
*/
3231
public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineImageShadowNode {
@@ -113,5 +112,4 @@ public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
113112
public @Nullable Object getCallerContext() {
114113
return mCallerContext;
115114
}
116-
117115
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include_defs('//ReactAndroid/DEFS')
2+
3+
# This target is only used in open source
4+
if IS_OSS_BUILD:
5+
cxx_library(
6+
name = 'jni',
7+
soname = 'libcsslayout.$(ext)',
8+
srcs = glob(['jni/*.cpp']),
9+
header_namespace = '',
10+
compiler_flags = [
11+
'-fno-omit-frame-pointer',
12+
'-fexceptions',
13+
'-Wall',
14+
'-Werror',
15+
'-O3',
16+
'-std=c++11',
17+
],
18+
deps = [
19+
'//ReactCommon/CSSLayout:CSSLayout',
20+
FBJNI_TARGET,
21+
],
22+
visibility = ['PUBLIC'],
23+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
include_defs('//ReactAndroid/DEFS')
2+
3+
# This target is only used in open source
4+
if IS_OSS_BUILD:
5+
cxx_library(
6+
name = 'jni',
7+
soname = 'libfb.$(ext)',
8+
srcs = glob(['*.cpp', 'jni/*.cpp', 'lyra/*.cpp']),
9+
header_namespace = '',
10+
compiler_flags = [
11+
'-fno-omit-frame-pointer',
12+
'-fexceptions',
13+
'-Wall',
14+
'-Werror',
15+
'-std=c++11',
16+
'-DDISABLE_CPUCAP',
17+
'-DDISABLE_XPLAT',
18+
],
19+
exported_headers = subdir_glob([
20+
('include', 'fb/**/*.h'),
21+
('include', 'jni/*.h'),
22+
]),
23+
deps = [
24+
JNI_TARGET,
25+
],
26+
visibility = ['PUBLIC'],
27+
)

‎ReactAndroid/src/test/java/com/facebook/react/BUCK‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include_defs('//ReactAndroid/DEFS')
22

3-
robolectric3_test(
3+
rn_robolectric_test(
44
name = 'react',
55
# Please change the contact to the oncall of your team
66
contacts = ['oncall+fbandroid_sheriff@xmail.facebook.com'],

‎ReactAndroid/src/test/java/com/facebook/react/animated/BUCK‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include_defs('//ReactAndroid/DEFS')
22

3-
robolectric3_test(
3+
rn_robolectric_test(
44
name = 'animated',
55
# Please change the contact to the oncall of your team
66
contacts = ['oncall+fbandroid_sheriff@xmail.facebook.com'],

‎ReactAndroid/src/test/java/com/facebook/react/bridge/BUCK‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android_library(
1919
],
2020
)
2121

22-
robolectric3_test(
22+
rn_robolectric_test(
2323
name = 'bridge',
2424
# Please change the contact to the oncall of your team
2525
contacts = ['oncall+fbandroid_sheriff@xmail.facebook.com'],

0 commit comments

Comments
 (0)