Files
react-native/ReactAndroid/src/androidTest/js/UIManagerTestModule.js
T
Andy StreetandFacebook Github Bot d63ba47b59 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
2016-11-21 06:28:30 -08:00

202 lines
4.9 KiB
JavaScript

/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule UIManagerTestModule
*/
'use strict';
var BatchedBridge = require('BatchedBridge');
var React = require('React');
var StyleSheet = require('StyleSheet');
var View = require('View');
var Text = require('Text');
var renderApplication = require('renderApplication');
var FlexTestApp = React.createClass({
_styles: StyleSheet.create({
container: {
width: 200,
height: 200,
flexDirection: 'row',
},
child: {
flex: 1,
},
absolute: {
position: 'absolute',
top: 15,
left: 10,
width: 50,
height: 60,
}
}),
render: function() {
return (
<View style={this._styles.container} testID="container" collapsable={false}>
<View style={[this._styles.child, {backgroundColor: '#ff0000'}]} collapsable={false}/>
<View style={[this._styles.child, {backgroundColor: '#0000ff'}]} collapsable={false}/>
</View>
);
}
});
var FlexWithText = React.createClass({
_styles: StyleSheet.create({
container: {
flexDirection: 'column',
margin: 20,
},
row: {
flexDirection: 'row',
alignItems: 'flex-end',
height: 300,
},
inner: {
flex: 1,
margin: 10,
},
}),
render: function() {
return (
<View style={this._styles.container} testID="container" collapsable={false}>
<View style={this._styles.row} collapsable={false}>
<Text style={this._styles.inner}>Hello</Text>
<Text style={this._styles.inner}>World</Text>
</View>
</View>
);
}
});
var AbsolutePositionTestApp = React.createClass({
_styles: StyleSheet.create({
absolute: {
position: 'absolute',
top: 15,
left: 10,
width: 50,
height: 60,
}
}),
render: function() {
return <View style={this._styles.absolute} testID="absolute" collapsable={false}/>;
}
});
var AbsolutePositionBottomRightTestApp = React.createClass({
_styles: StyleSheet.create({
container: {
width: 100,
height: 100,
},
absolute: {
position: 'absolute',
bottom: 15,
right: 10,
width: 50,
height: 60,
}
}),
render: function() {
return (
<View style={this._styles.container} testID="container" collapsable={false}>
<View style={this._styles.absolute} collapsable={false}/>
</View>
);
}
});
var CenteredTextView = React.createClass({
_styles: StyleSheet.create({
parent: {
width: 200,
height: 100,
backgroundColor: '#aa3311',
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 15,
color: '#672831',
},
}),
render: function() {
return (
<View collapsable={false}>
<View style={this._styles.parent} collapsable={false}>
<Text style={this._styles.text} testID="text">{this.props.text}</Text>
</View>
</View>
);
}
});
var flushUpdatePositionInList = null;
var UpdatePositionInListTestApp = React.createClass({
_styles: StyleSheet.create({
element: {
height: 10,
},
active: {
height: 50,
}
}),
getInitialState: function() {
flushUpdatePositionInList = () => this.setState({ active: true });
return { active: false };
},
render: function() {
return (
<View collapsable={false} testID="container">
<View style={this._styles.element} collapsable={false} />
<View
style={[
this._styles.element,
this.state.active && this._styles.active,
]}
collapsable={false}
/>
<View style={this._styles.element} collapsable={false}/>
</View>
);
}
});
var UIManagerTestModule = {
renderFlexTestApplication: function(rootTag) {
renderApplication(FlexTestApp, {}, rootTag);
},
renderFlexWithTextApplication: function(rootTag) {
renderApplication(FlexWithText, {}, rootTag);
},
renderAbsolutePositionBottomRightTestApplication: function(rootTag) {
renderApplication(AbsolutePositionBottomRightTestApp, {}, rootTag);
},
renderAbsolutePositionTestApplication: function(rootTag) {
renderApplication(AbsolutePositionTestApp, {}, rootTag);
},
renderCenteredTextViewTestApplication: function(rootTag, text) {
renderApplication(CenteredTextView, {text: text}, rootTag);
},
renderUpdatePositionInListTestApplication: function(rootTag) {
renderApplication(UpdatePositionInListTestApp, {}, rootTag);
},
flushUpdatePositionInList: function() {
flushUpdatePositionInList();
}
};
BatchedBridge.registerCallableModule(
'UIManagerTestModule',
UIManagerTestModule
);
module.exports = UIManagerTestModule;