React native layout attention point

Source: Internet
Author: User


One, react native many are ES6 grammar. 1 lines. The expression is the strict mode of JS

‘Use strict’;
In strict mode, variables must be declared first, and then assigned, defined, etc .;
There is this binding.
2 to 8 lines. Import dependencies can be understood as import XX.react-native.React; and import XX.react-native.React.AppRegistry; in Java. 9 lines. Custom components, components are the basic elements of React Native, can be compared to Activity. 10 to 24 lines. The render () method, my understanding is used to render the page. The xml and layout inside are similar and are used for layout. Line 26 to line 43. Through the StyleSheet.create () method, a set of attributes required for layout is generated. Add style attribute to <View /> etc. in render (). Analogously, the attributes of each View in Android are realized through style, and the attribute set we create is the style set. 44 lines. Register custom components. Second, the click event in react native generally uses Touchable components
  Among them are commonly used TouchableHighlight and TouchableOpacity
TouchableHighlight is the change in background transparency
TouchableOpacity The transparency of the text or picture itself

Note: Touchable component series can only contain one child component, that is to say you want multiple, you can nest View component to achieve. Such as:

 
<TouchableHighlight>
      <View>
            <Text> t1 </ Text>
    <Text> t2 </ Text>
      </ View>
</ TouchableHighlight>
 

 Three, page jump First of all, we must configure the page jump controller as follows:
render () {
  return (
    <Navigator
      initialRoute = {{id: ‘Page‘}}
      renderScene = {this.actionTo} />
  );
},
actionTo (route, navigator) {
  switch (route.id) {
    case ‘Page‘:
      return (<Page navigator = {navigator} />);
    case ‘Page2’:
      return (<Page2 navigator = {navigator} />);
  }
}
  Navigator is the page jump controller, initialRoute refers to the initial page, renderScene is the method of callback when the page jumps, here is the actionTo method.

    The actionTo method is to jump to different pages through the route attribute, which can be understood in this way. When you need to jump to the next page, just call the following method
 this.props.navigator.push ({
   id: ‘Page2’,
 });
 

   
Notes on react native layout

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.