forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary:I will fix other notes from facebook#2794 if I get positive feedback. Closes facebook#6061 Reviewed By: nicklockwood Differential Revision: D2982173 Pulled By: dmmiller fb-gh-sync-id: d1e9407798b0293b090897a10996085b0f0c1b3e shipit-source-id: d1e9407798b0293b090897a10996085b0f0c1b3e
- Loading branch information
1 parent
e39dc94
commit 59bc8cb
Showing
13 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* The examples provided by Facebook are for non-commercial testing and | ||
* evaluation purposes only. | ||
* | ||
* Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
var React = require('react-native'); | ||
var { | ||
StyleSheet, | ||
View, | ||
Text, | ||
TouchableHighlight, | ||
Vibration, | ||
} = React; | ||
|
||
exports.framework = 'React'; | ||
exports.title = 'Vibration'; | ||
exports.description = 'Vibration API'; | ||
exports.examples = [{ | ||
title: 'Vibration.vibrate()', | ||
render() { | ||
return ( | ||
<TouchableHighlight | ||
style={styles.wrapper} | ||
onPress={() => Vibration.vibrate()}> | ||
<View style={styles.button}> | ||
<Text>Vibrate</Text> | ||
</View> | ||
</TouchableHighlight> | ||
); | ||
}, | ||
}]; | ||
|
||
var styles = StyleSheet.create({ | ||
wrapper: { | ||
borderRadius: 5, | ||
marginBottom: 5, | ||
}, | ||
button: { | ||
backgroundColor: '#eeeeee', | ||
padding: 10, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule Vibration | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
var RCTVibration = require('NativeModules').Vibration; | ||
var Platform = require('Platform'); | ||
|
||
/** | ||
* The Vibration API is exposed at `Vibration.vibrate()`. | ||
* The vibration is asynchronous so this method will return immediately. | ||
* | ||
* There will be no effect on devices that do not support Vibration, eg. the simulator. | ||
* | ||
* Note for android | ||
* add `<uses-permission android:name="android.permission.VIBRATE"/>` to `AndroidManifest.xml` | ||
* | ||
* Vibration patterns are currently unsupported. | ||
*/ | ||
|
||
var Vibration = { | ||
vibrate: function(duration: number = 400) { | ||
if (Platform.OS === 'android') { | ||
RCTVibration.vibrate(duration); | ||
} else { | ||
RCTVibration.vibrate(); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = Vibration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
ReactAndroid/src/main/java/com/facebook/react/modules/vibration/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
include_defs('//ReactAndroid/DEFS') | ||
|
||
android_library( | ||
name = 'vibration', | ||
srcs = glob(['**/*.java']), | ||
deps = [ | ||
react_native_target('java/com/facebook/react/bridge:bridge'), | ||
react_native_target('java/com/facebook/react/common:common'), | ||
react_native_target('java/com/facebook/react/modules/core:core'), | ||
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'), | ||
react_native_dep('third-party/java/infer-annotations:infer-annotations'), | ||
react_native_dep('third-party/java/jsr-305:jsr-305'), | ||
], | ||
visibility = [ | ||
'PUBLIC', | ||
], | ||
) | ||
|
||
project_config( | ||
src_target = ':vibration', | ||
) |
37 changes: 37 additions & 0 deletions
37
ReactAndroid/src/main/java/com/facebook/react/modules/vibration/VibrationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.modules.vibration; | ||
|
||
import android.content.Context; | ||
import android.os.Vibrator; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
public class VibrationModule extends ReactContextBaseJavaModule { | ||
|
||
public VibrationModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Vibration"; | ||
} | ||
|
||
@ReactMethod | ||
public void vibrate(int duration) { | ||
Vibrator v = (Vibrator) getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); | ||
if (v != null) { | ||
v.vibrate(duration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters