• Handling Touches


    1. basic button

       format:

        <tag event caption />

    <Button 
        onPress={{}}
        title="I am button"
     />
            <Button 
                onPress={() => {
                    Alert.alert("You are Right!");
                }}
                title="Push me"
            />

    Usage:

    (1) import

    import {Button, Alert} from "react-native";


    (2) src

    import React from 'react';
    import { StyleSheet, Text, View, Button, Alert } from 'react-native';
    
    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>
            <Button 
                onPress={() => {
                    Alert.alert("You are Right!");
                }}
                title="Push me"
            />
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
      },
    });

    2. Actual button

        format:

         <tag event caption />

            <TouchableHighlight event>
              <View>
                <Text>caption</Text>
              </View>
            </TouchableHighlight>

    for example:

            <TouchableHighlight onPress={this._onPressButton} underlayColor="white">
              <View style={styles.button}>
                <Text style={styles.buttonText}>I am a rounded button</Text>
              </View>
            </TouchableHighlight>

    Usage:

    (1) import

    import {Platform, TouchableHightlight} from "react-native"

    (2) src

    import React from 'react';
    import { StyleSheet, Text, View, Platform, TouchableHighlight, Alert } from 'react-native';
    
    export default class App extends React.Component {
      _onPressButton() {
        Alert.alert('You tapped the button!')
      }
    
      render() {
        return (
          <View style={styles.container}>
            <TouchableHighlight onPress={this._onPressButton} underlayColor="white">
              <View style={styles.button}>
                <Text style={styles.buttonText}>I am a rounded button</Text>
              </View>
            </TouchableHighlight>
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        paddingTop: 60,
        alignItems: 'center'
      },
      button: {
        marginBottom: 30,
         260,
        alignItems: 'center',
        backgroundColor: '#2196F3',
        borderRadius:10
      },
      buttonText: {
        padding: 20,
        color: 'white'
      }
    });

    Reference:

      1. Handling Touches - Displaying a basic button

      2. Handling Touches - Touchables

  • 相关阅读:
    Delphi 拖动
    Unknown picture file extension
    鼠标指针形状
    C_FD_PhysRDBMSKinds
    delphichromiumembedded
    delphi使用 DockForm DesignEditors F2613 Unit 'DockForm' not found
    TBitConverter
    sql 存储过程返回值 变量名
    XE7 数据库独立运行需要的文件
    C++Builder 内存泄露检测
  • 原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/10575828.html
Copyright © 2020-2023  润新知