zoukankan      html  css  js  c++  java
  • React Native

    有时程序中需要实现这样的功能,当有重要的消息提醒时,我们会发出声音告知用户。而如果用户关闭了声音,那么就可以改用振动来提醒用户。

    使用 React Native 提供的 Vibration API,我们可以很方便地让移动设备发生振动效果
    点击界面上的“点击震动”按钮,设备会出现1秒钟的震动效果。
    (注意:需要使用真机调试,模拟器没有效果)

    样例代码

    import React from 'react';
    import {
        AppRegistry,
        StyleSheet,
        Text,
        View,
        Vibration
    } from 'react-native';
     
     
    //默认应用的容器组件
    export default class ShakeMode extends React.Component {
    
        static navigationOptions = ({ navigation }) => {
            const { navigate } = navigation;
            return {
                title: '震动手机'
            };
        };
    
       //渲染
        render() {
            return (
                <View style={styles.container}>
                    <Text style={styles.item} onPress={this.vibration.bind(this)}>点击震动</Text>
                </View>
            );
        }
     
        //点击震动
        vibration() {
            Vibration.vibrate();
        }
    }
     
    //样式定义
    const styles = StyleSheet.create({
        container:{
            flex: 1,
            marginTop:25
        },
        item:{
            margin:15,
            height:30,
            borderWidth:1,
            padding:6,
            borderColor:'#ddd',
            textAlign:'center'
        },
    });
     

     

  • 相关阅读:
    Android smali 语法
    iOS 发布计费点测试
    how-to-stop-non-jailbroken-pirates-theory
    shell script
    文章收藏
    NB BAT批量读取图片文件属性
    JAVA LUHN
    MAC NDK 编译 Cocos2dx 问题
    Mac 下解压缩安装Android ndk bin 文件
    MVC Json输出调试信息
  • 原文地址:https://www.cnblogs.com/haonanZhang/p/7553031.html
Copyright © 2011-2022 走看看