非常教程

React native参考手册

APIs

Vibration

振动API暴露于Vibration.vibrate()。振动是异步的,所以此方法将立即返回。

对不支持振动的设备没有影响,例如。模拟器。

Android注意事项:添加<uses-permission android:name="android.permission.VIBRATE"/>AndroidManifest.xml

由于iOS中振动持续时间不可配置,因此与Android有一些差异。在Android中,如果pattern是数字,则指定振动持续时间(以毫秒为单位)。如果pattern是一个阵列,那些奇数指数是振动持续时间,而偶数指数是分离时间。

在iOS中,调用vibrate(duration)只会忽略持续时间并在固定时间内振动。虽然pattern阵列被用来定义每个振动之间的持续时间。请参阅下面的示例了解更多

也支持可重复的振动,振动将以定义的模式重复,直到cancel()被调用。

例:

const DURATION = 10000
const PATTERN = [1000, 2000, 3000]

Vibration.vibrate(DURATION)
// Android: vibrate for 10s
// iOS: duration is not configurable, vibrate for fixed time (about 500ms)

Vibration.vibrate(PATTERN)
// Android: wait 1s -> vibrate 2s -> wait 3s
// iOS: wait 1s -> vibrate -> wait 2s -> vibrate -> wait 3s -> vibrate

Vibration.vibrate(PATTERN, true)
// Android: wait 1s -> vibrate 2s -> wait 3s -> wait 1s -> vibrate 2s -> wait 3s -> ...
// iOS: wait 1s -> vibrate -> wait 2s -> vibrate -> wait 3s -> vibrate -> wait 1s -> vibrate -> wait 2s -> vibrate -> wait 3s -> vibrate -> ...

Vibration.cancel()
// Android: vibration stopped
// iOS: vibration stopped

方法

static vibrate(pattern:number,Array <number>,repeat:boolean)

触发指定的振动pattern

参数:

名称和类型

描述

patternnumber | 阵列<编号>

振动模式,接受一个数字或一组数字。默认为400ms。

repeatboolean

可选的。重复振动模式,直到cancel(),默认为false。

static cancel()

停止振动

Vibration.cancel()
React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous