Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { StatusBar } from 'expo-status-bar';
  2. import React from 'react';
  3. import { StyleSheet, Text, View, Button, TouchableOpacity, FlatList } from 'react-native';
  4.  
  5. import {
  6.     Header,
  7.     LearnMoreLinks,
  8.     Colors,
  9.     DebugInstructions,
  10.     ReloadInstructions,
  11. } from 'react-native/Libraries/NewAppScreen';
  12.  
  13. const colorList = [
  14.     { key: '1', value: 'blueviolet' },
  15.     { key: '2', value: 'chartreuse' },
  16.     { key: '3', value: 'cyan' },
  17.     { key: '4', value: 'darggrey' },
  18.     { key: '5', value: 'gold' },
  19.     { key: '6', value: 'khaki' },
  20.     { key: '7', value: 'lawngreen' },
  21.     { key: '8', value: 'orange' },
  22.     { key: '9', value: 'palevioletred' },
  23.     { key: '10', value: 'yellow' },
  24. ];
  25.  
  26. export default class App extends React.Component {
  27.     constructor(props) {
  28.         super(props);    
  29.         this.state = { clicks: 0, color: 'blue', changeBackgroundColor: 'green', changeBackgroundColorList: 'green'};      
  30.     }
  31.  
  32.     increase = this.increase.bind(this)
  33.     decrease = this.decrease.bind(this)
  34.  
  35.     increase() {
  36.         this.setState({ color: 'white' });
  37.         this.setState(previousState => ({ clicks: previousState.clicks + 1 }));
  38.     }
  39.  
  40.     decrease() {
  41.         this.setState({ color: 'white' });
  42.         this.setState(previousState => ({ clicks: previousState.clicks - 1 }));
  43.     }
  44.  
  45.     onLongClick = this.onLongClick.bind(this);
  46.     onClick = this.onClick.bind(this);
  47.  
  48.     onLongClick() {
  49.         this.setState({ changeBackgroundColor: 'white'  });
  50.     }
  51.  
  52.     onClick() {
  53.         var randomColor = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
  54.         this.setState({ changeBackgroundColor: randomColor });
  55.     }
  56.  
  57.     onClickList = this.onClickList.bind(this);
  58.  
  59.     onClickList() {
  60.         this.setState({ changeBackgroundColorList: colorList[this.selectColor].value });
  61.     }
  62.  
  63.     render() {
  64.         return (
  65.             <View style={{ flex: 1 }}>
  66.                 <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  67.                     <Text>{"\n"}</Text>
  68.                     <Text style={styles.header}>Klikacz</Text>
  69.                 </View>
  70.                 <View style={{ flex: 3, justifyContent: 'center' }}>
  71.                     <Text style={styles.counter}>Liczba klikniec: {this.state.clicks}</Text>
  72.                     <Text>{"\n"}</Text>
  73.                     <View style={styles.buttons}>
  74.                         <Button title="Dodaj" onPress={this.increase} />
  75.                         <Text>{"\t"}</Text>
  76.                         <Button title="Odejmij" onPress={this.decrease} />
  77.                     </View>
  78.                 </View>
  79.                 <View style={{ flex: 3, justifyContent: 'center', alignItems: 'center', backgroundColor: this.state.changeBackgroundColor }}>
  80.                     <TouchableOpacity onPress={this.onClick} onLongPress={this.onLongClick}>
  81.                         <Text>
  82.                             <Text style={styles.changeText}>Zmien tlo</Text>
  83.                         </Text>
  84.                     </TouchableOpacity>
  85.                 </View>
  86.                 <View style={{ flex: 2, justifyContent: 'center', alignItems: 'center', backgroundColor: this.state.changeBackgroundColorList }}>
  87.                     <FlatList
  88.                         data={colorList}
  89.                         renderItem={({ item }) =>
  90.                             <Text style={styles.item} onPress={this.selectColor.bind(this, item)}>{item.value}</Text>}
  91.                     />
  92.                 </View>
  93.             </View>
  94.         );
  95.     }
  96. }
  97.  
  98. const styles = StyleSheet.create({
  99.     header: {
  100.         fontSize: 36,
  101.         fontWeight: 'bold',
  102.         color: 'black',
  103.         textAlign: 'center',
  104.         alignItems: 'center',
  105.         justifyContent: 'center',
  106.     },
  107.     counter: {
  108.         fontSize: 24,
  109.         fontWeight: 'bold',
  110.         color: 'blue',
  111.         textAlign: 'center',
  112.         alignItems: 'center',
  113.         justifyContent: 'center',
  114.     },
  115.     buttons: {
  116.         width: '100%',
  117.         flexDirection: 'row',
  118.         justifyContent: 'center',
  119.         alignItems: 'center'
  120.     },
  121.     changeBackground: {
  122.        
  123.     },
  124.     changeTouchable: {
  125.         justifyContent: 'center',
  126.         alignItems: 'center',
  127.         backgroundColor: 'red'
  128.     },
  129.     changeText: {
  130.         fontSize: 24,
  131.         fontWeight: 'bold',
  132.         color: 'blue',
  133.         textAlign: 'center'
  134.     },
  135.     item: {
  136.         fontSize: 16,
  137.         color: 'blue'
  138.     }
  139. });
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement