Browse Source

0.0.5 StyleSheet component. Split to multiple example files.

Frederic G. MARAND 6 years ago
parent
commit
3c21d13b7a
7 changed files with 169 additions and 106 deletions
  1. 4 106
      App.js
  2. 20 0
      App01Hello.js
  3. 26 0
      App02Bananas.js
  4. 29 0
      App03Greetings.js
  5. 45 0
      App04Blink.js
  6. 33 0
      App05Styles.js
  7. 12 0
      styles.js

+ 4 - 106
App.js

@@ -1,110 +1,8 @@
-import React, { Component } from 'react';
-import {
-  // AppRegistry,
-  Image,
-  StyleSheet,
-  Text,
-  View
-} from 'react-native';
+// import { AppRegistry } from 'react-native';
 
-const styles = StyleSheet.create({
-  container: {
-    flex: 1,
-    backgroundColor: '#f92',
-    alignItems: 'center',
-    justifyContent: 'center',
-  },
-});
+import App from './App05Styles';
 
-class App extends Component {
-  render() {
-    return (
-      <View style={styles.container}>
-        <Text>Open up App.js to start working on your app!</Text>
-        <Text>Changes you make will automatically reload.</Text>
-        <Text>Shake your phone to open the developer menu.</Text>
-      </View>
-    );
-  }
-}
-
-
-class Bananas extends Component {
-  render() {
-    const pic = {
-      uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg',
-    };
-    const img = (
-      <Image source={pic} style={{
-        backgroundColor: 'orange',
-        height: 110,
-        opacity: 0.9,
-        width: '100%',
-      }} />
-    );
-
-    return (
-      img
-    );
-  }
-}
-
-class Greeting extends Component {
-  render() {
-    return (
-      <Text>Hello {this.props.name}!</Text>
-    );
-  }
-}
-
-class LotfOfGreetings extends Component {
-  render() {
-    return (
-      <View style={styles.container}>
-        <Greeting name="Rexxar" />
-        <Greeting name="Jaina" />
-        <Greeting name="Valeera" />
-      </View>
-    );
-  }
-}
-
-class Blink extends Component {
-  constructor(props) {
-    super(props);
-    this.state = { isShowingText: true };
-
-    setInterval(() => {
-      this.setState(previousState => ({
-        isShowingText: !previousState.isShowingText,
-      }));
-    }, 1000);
-  }
-
-  render() {
-    const display = this.state.isShowingText
-      ? this.props.text
-      : ' ';
-
-
-    return (
-      <Text>{display}</Text>
-    );
-  }
-}
-
-export default class BlinkApp extends Component {
-  render() {
-    return (
-      <View style={styles.container}>
-        <Blink text="I love to blink" />
-        <Blink text="Yes blinking is so great" />
-        <Blink text="Why did they ever take this out of HTML" />
-        <Blink text="Look at me look at me look at me" />
-      </View>
-    );
-  }
-}
+export default App;
 
 // skip this line if using Create React Native App
-// AppRegistry.registerComponent('AwesomeProject', () => Bananas);
+// AppRegistry.registerComponent('AwesomeProject', () => App);

+ 20 - 0
App01Hello.js

@@ -0,0 +1,20 @@
+import React from "react";
+import {
+  Text,
+  View,
+} from 'react-native';
+
+import styles from './styles';
+
+export default class App extends React.Component {
+  render() {
+    return (
+      <View style={styles.container}>
+        <Text>Open up App.js to start working on your app!</Text>
+        <Text>Changes you make will automatically reload.</Text>
+        <Text>Shake your phone to open the developer menu.</Text>
+      </View>
+    );
+  }
+}
+

+ 26 - 0
App02Bananas.js

@@ -0,0 +1,26 @@
+import React from "react";
+import {
+  Image,
+} from 'react-native';
+
+class Bananas extends React.Component {
+  render() {
+    const pic = {
+      uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg',
+    };
+    const img = (
+      <Image source={pic} style={{
+        backgroundColor: 'orange',
+        height: 110,
+        opacity: 0.9,
+        width: '100%',
+      }} />
+    );
+
+    return (
+      img
+    );
+  }
+}
+
+export default Bananas;

+ 29 - 0
App03Greetings.js

@@ -0,0 +1,29 @@
+import React from "react";
+import {
+  Text,
+  View,
+} from 'react-native';
+
+import styles from "./styles";
+
+class Greeting extends React.Component {
+  render() {
+    return (
+      <Text>Hello {this.props.name}!</Text>
+    );
+  }
+}
+
+class LotfOfGreetings extends React.Component {
+  render() {
+    return (
+      <View style={styles.container}>
+        <Greeting name="Rexxar" />
+        <Greeting name="Jaina" />
+        <Greeting name="Valeera" />
+      </View>
+    );
+  }
+}
+
+export default LotfOfGreetings;

+ 45 - 0
App04Blink.js

@@ -0,0 +1,45 @@
+import React from "react";
+import {
+  Text,
+  View,
+} from 'react-native';
+
+import styles from "./styles";
+
+class Blink extends React.Component {
+  constructor(props) {
+    super(props);
+    this.state = { isShowingText: true };
+
+    setInterval(() => {
+      this.setState(previousState => ({
+        isShowingText: !previousState.isShowingText,
+      }));
+    }, 1000);
+  }
+
+  render() {
+    const display = this.state.isShowingText
+      ? this.props.text
+      : ' ';
+
+
+    return (
+      <Text>{display}</Text>
+    );
+  }
+}
+
+export default class BlinkApp extends React.Component {
+  render() {
+    return (
+      <View style={styles.container}>
+        <Blink text="I love to blink" />
+        <Blink text="Yes blinking is so great" />
+        <Blink text="Why did they ever take this out of HTML" />
+        <Blink text="Look at me look at me look at me" />
+      </View>
+    );
+  }
+}
+

+ 33 - 0
App05Styles.js

@@ -0,0 +1,33 @@
+import React from "react";
+import {
+  StyleSheet,
+  Text,
+  View,
+} from 'react-native';
+
+
+const styles = StyleSheet.create({
+  bigblue: {
+    color: 'blue',
+    fontWeight: 'bold',
+    fontSize: 30,
+  },
+  red: {
+    color: 'red',
+  },
+});
+
+class LotsOfStyles extends React.Component {
+  render() {
+    return (
+      <View>
+        <Text style={styles.bigblue}>Just big blue</Text>
+        <Text style={styles.red}>Just red</Text>
+        <Text style={[styles.bigblue, styles.red]}>Big blue, then red</Text>
+        <Text style={[styles.red, styles.bigblue]}>Red, then big blue</Text>
+      </View>
+    );
+  }
+}
+
+export default LotsOfStyles;

+ 12 - 0
styles.js

@@ -0,0 +1,12 @@
+import { StyleSheet } from "react-native";
+
+const styles = StyleSheet.create({
+  container: {
+    flex: 1,
+    backgroundColor: '#f93',
+    alignItems: 'center',
+    justifyContent: 'center',
+  },
+});
+
+export default styles;