SlideShare a Scribd company logo
React - Native
Basic
• Props
• State
• Style
• Height and width
• FlexBox
• Touch
Props
• Components can be customized at creation time. These customized
parameters are called props.
<ClassB text={‘Hello world’} />
Here text is props.
• In ClassB, for using text, we can write:
Const text = this.props.text
Const {text} = this.props;
State
• Data, that is going to change, we use state.
• You should initialize state in the constructor.
this.state = {isShowingText: true};
• Call setState when you want to change it.
this.setState(previousState => {
return { isShowingText: !previousState.isShowingText };
});
Or
this.setState( { isShowingText: !this.state.isShowingText });
• When we want to use state data:
const isShowingText = this.state.isShowingText;
Props Vs State
• There are two types of data that control a component.
• Props: props are set by the parent and they are fixed throughout the
lifetime of a component.
• State: For data that is going to change, we have to use state.
Style
• style props is used for styling a component. StyleSheet.create is sued
to create all style at a place.
const styles = StyleSheet.create({
bigblue: {
color: 'blue’
},
red: {
color: 'red',
},
});
Height and width
• The simplest way to set the dimensions of a component is by adding a
fixed width and height to style.
<View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
• Use flex in a component's style to have the component expand and shrink
dynamically based on available space
<View style={{flex: 1, backgroundColor: 'powderblue'}} />
<View style={{flex: 2, backgroundColor: 'skyblue'}} />
<View style={{flex: 3, backgroundColor: 'steelblue'}} />
FlexBox
• To accommodate different screen sizes, React Native offers Flexbox
support. To achieve the desired layout, flexbox offers three main
properties:
• flexDirection: Used to align element vertical or horizontal
• justifyContent: Used to determine elements distribution inside a
container along the primary axis
• alignItems: Used to determine elements distribution inside a
container along the secondary axis
flexDirection
• Adding flexDirection to a component's style determines the primary
axis of its layout.
<View style={{flex: 1, flexDirection: 'row'}}>
justifyContent
• Adding justifyContent to a component's style determines
the distribution of children along the primary axis.
• Values:
flex-start
• center
• flex-end
• space-around
• space-between
• space-evenly
<View style={{
flex: 1,
flexDirection: 'column',
alignItems
• Adding alignItems to a component's style determines the alignment of
children along the secondary axis
• Values:
• flex-start
• center
• flex-end
• stretch
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}>
Touch
• We can handle touch using following components:
• Button
<Button onPress={() => { Alert.alert('You tapped the button!'); }}
title="Press Me" />
• TouchableHeightLight: Change background color on touch
• TouchableOpacity: Change opacity on touch
• TouchableWithoutFeedback: No effect
< TouchableWithoutFeedback onPress={() => { Alert.alert('You tapped the button!'); }} >
<View />
</ TouchableWithoutFeedback >

More Related Content

PPTX
Save data locally
PPTX
Database compatibility
PDF
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
PDF
CSS Conf Budapest - New CSS Layout
PDF
But what about old browsers?
PPTX
Designing Windows apps with Xaml
PDF
A complete guide to flexbox
PDF
The Right Layout Tool for the Job
Save data locally
Database compatibility
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
CSS Conf Budapest - New CSS Layout
But what about old browsers?
Designing Windows apps with Xaml
A complete guide to flexbox
The Right Layout Tool for the Job

Similar to 2. react - native: basic (20)

PDF
Flexbox and Grid Layout
PDF
Future Layout & Performance
PDF
Understanding Flexbox Layout in React Native.pdf
PDF
React-Native Lecture 11: In App Storage
PDF
The New CSS Layout - dotCSS
PDF
Flexbox, Grid and Sass
PPTX
Flex box
PPTX
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
PPTX
sesion4SDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
PPTX
MTA css layouts
PPTX
Basics of expression blend4
PDF
ConFoo 2016: Making Sense of CSS Layout
PPTX
flexbox report
PDF
Fluent: Making Sense of the New CSS Layout
PDF
Adobe Flex - Developing Rich Internet Application Workshop Day 2
PPTX
Lecture-9.pptx
PPTX
CSS3 Flex Layout
PPTX
digital swifton
PPTX
WPF Line of Business Application XAML Layouts Presentation
PPTX
DSpace 4.2 XMLUI Theming
Flexbox and Grid Layout
Future Layout & Performance
Understanding Flexbox Layout in React Native.pdf
React-Native Lecture 11: In App Storage
The New CSS Layout - dotCSS
Flexbox, Grid and Sass
Flex box
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
sesion4SDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
MTA css layouts
Basics of expression blend4
ConFoo 2016: Making Sense of CSS Layout
flexbox report
Fluent: Making Sense of the New CSS Layout
Adobe Flex - Developing Rich Internet Application Workshop Day 2
Lecture-9.pptx
CSS3 Flex Layout
digital swifton
WPF Line of Business Application XAML Layouts Presentation
DSpace 4.2 XMLUI Theming
Ad

Recently uploaded (6)

PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
PPTX
ASMS Telecommunication company Profile
PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
ASMS Telecommunication company Profile
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Ad

2. react - native: basic

  • 2. • Props • State • Style • Height and width • FlexBox • Touch
  • 3. Props • Components can be customized at creation time. These customized parameters are called props. <ClassB text={‘Hello world’} /> Here text is props. • In ClassB, for using text, we can write: Const text = this.props.text Const {text} = this.props;
  • 4. State • Data, that is going to change, we use state. • You should initialize state in the constructor. this.state = {isShowingText: true}; • Call setState when you want to change it. this.setState(previousState => { return { isShowingText: !previousState.isShowingText }; }); Or this.setState( { isShowingText: !this.state.isShowingText }); • When we want to use state data: const isShowingText = this.state.isShowingText;
  • 5. Props Vs State • There are two types of data that control a component. • Props: props are set by the parent and they are fixed throughout the lifetime of a component. • State: For data that is going to change, we have to use state.
  • 6. Style • style props is used for styling a component. StyleSheet.create is sued to create all style at a place. const styles = StyleSheet.create({ bigblue: { color: 'blue’ }, red: { color: 'red', }, });
  • 7. Height and width • The simplest way to set the dimensions of a component is by adding a fixed width and height to style. <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} /> • Use flex in a component's style to have the component expand and shrink dynamically based on available space <View style={{flex: 1, backgroundColor: 'powderblue'}} /> <View style={{flex: 2, backgroundColor: 'skyblue'}} /> <View style={{flex: 3, backgroundColor: 'steelblue'}} />
  • 8. FlexBox • To accommodate different screen sizes, React Native offers Flexbox support. To achieve the desired layout, flexbox offers three main properties: • flexDirection: Used to align element vertical or horizontal • justifyContent: Used to determine elements distribution inside a container along the primary axis • alignItems: Used to determine elements distribution inside a container along the secondary axis
  • 9. flexDirection • Adding flexDirection to a component's style determines the primary axis of its layout. <View style={{flex: 1, flexDirection: 'row'}}>
  • 10. justifyContent • Adding justifyContent to a component's style determines the distribution of children along the primary axis. • Values: flex-start • center • flex-end • space-around • space-between • space-evenly <View style={{ flex: 1, flexDirection: 'column',
  • 11. alignItems • Adding alignItems to a component's style determines the alignment of children along the secondary axis • Values: • flex-start • center • flex-end • stretch <View style={{ flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'center', }}>
  • 12. Touch • We can handle touch using following components: • Button <Button onPress={() => { Alert.alert('You tapped the button!'); }} title="Press Me" /> • TouchableHeightLight: Change background color on touch • TouchableOpacity: Change opacity on touch • TouchableWithoutFeedback: No effect < TouchableWithoutFeedback onPress={() => { Alert.alert('You tapped the button!'); }} > <View /> </ TouchableWithoutFeedback >