react-native Vibration

/**

* Sample React Native App

* https://github.com/facebook/react-native

* @flow

*/

import React, { Component } from 'react';

import {

AppRegistry,

StyleSheet,

Text,

View,

InteractionManager,

PixelRatio,

Vibration

} from 'react-native';

export default class D20170504 extends Component {

render() {

return (

{

/**

* 需要真机测试

* ios 支持一次震动

* android 支持一次和多次震动

*/

}

{

Vibration.vibrate();

}}>{'一次震动'}

{

// 第一个 500 为震动 500 毫秒

// 200 为震动以后间隔 200 毫秒

// 第二个 500 间隔后在震动500 毫秒

Vibration.vibrate([0,500,200,500]);

}}>{'震动模式/android'}

{

//第二个参数为true = 连续/重复震动

Vibration.vibrate([0,500,200,500],true);

}}>{'重复震动/android'}

);

}

}

const styles = StyleSheet.create({

container: {

flex: 1,

justifyContent: 'center',

alignItems: 'center',

backgroundColor: '#F5FCFF',

},

welcome: {

fontSize: 20,

textAlign: 'center',

margin: 10,

},

instructions: {

textAlign: 'center',

color: '#333333',

marginBottom: 5,

},

});

AppRegistry.registerComponent('D20170504', () => D20170504);

你可能感兴趣的:(react-native Vibration)