App.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { Component } from 'react';
  2. import {
  3. // AppRegistry,
  4. Image,
  5. StyleSheet,
  6. Text,
  7. View
  8. } from 'react-native';
  9. const styles = StyleSheet.create({
  10. container: {
  11. flex: 1,
  12. backgroundColor: '#f92',
  13. alignItems: 'center',
  14. justifyContent: 'center',
  15. },
  16. });
  17. class App extends Component {
  18. render() {
  19. return (
  20. <View style={styles.container}>
  21. <Text>Open up App.js to start working on your app!</Text>
  22. <Text>Changes you make will automatically reload.</Text>
  23. <Text>Shake your phone to open the developer menu.</Text>
  24. </View>
  25. );
  26. }
  27. }
  28. class Bananas extends Component {
  29. render() {
  30. const pic = {
  31. uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg',
  32. };
  33. const img = (
  34. <Image source={pic} style={{
  35. backgroundColor: 'orange',
  36. height: 110,
  37. opacity: 0.9,
  38. width: '100%',
  39. }} />
  40. );
  41. return (
  42. img
  43. );
  44. }
  45. }
  46. class Greeting extends Component {
  47. render() {
  48. return (
  49. <Text>Hello {this.props.name}!</Text>
  50. );
  51. }
  52. }
  53. class LotfOfGreetings extends Component {
  54. render() {
  55. return (
  56. <View style={styles.container}>
  57. <Greeting name="Rexxar" />
  58. <Greeting name="Jaina" />
  59. <Greeting name="Valeera" />
  60. </View>
  61. );
  62. }
  63. }
  64. class Blink extends Component {
  65. constructor(props) {
  66. super(props);
  67. this.state = { isShowingText: true };
  68. setInterval(() => {
  69. this.setState(previousState => ({
  70. isShowingText: !previousState.isShowingText,
  71. }));
  72. }, 1000);
  73. }
  74. render() {
  75. const display = this.state.isShowingText
  76. ? this.props.text
  77. : ' ';
  78. return (
  79. <Text>{display}</Text>
  80. );
  81. }
  82. }
  83. export default class BlinkApp extends Component {
  84. render() {
  85. return (
  86. <View style={styles.container}>
  87. <Blink text="I love to blink" />
  88. <Blink text="Yes blinking is so great" />
  89. <Blink text="Why did they ever take this out of HTML" />
  90. <Blink text="Look at me look at me look at me" />
  91. </View>
  92. );
  93. }
  94. }
  95. // skip this line if using Create React Native App
  96. // AppRegistry.registerComponent('AwesomeProject', () => Bananas);