Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Examples/UIExplorer/UIExplorerList.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ const APIExamples = [
key: 'ToastAndroidExample',
module: require('./ToastAndroidExample'),
},
{
key: 'VibrationExample',
module: require('./VibrationExample'),
},
{
key: 'XHRExample',
module: require('./XHRExample'),
Expand Down
4 changes: 2 additions & 2 deletions Examples/UIExplorer/UIExplorerList.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ var APIExamples: Array<UIExplorerExample> = [
module: require('./TransformExample'),
},
{
key: 'VibrationIOSExample',
module: require('./VibrationIOSExample'),
key: 'VibrationExample',
module: require('./VibrationExample'),
},
{
key: 'XHRExample',
Expand Down
54 changes: 54 additions & 0 deletions Examples/UIExplorer/VibrationExample.js
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property Vibration Property not found in Object.create

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property Vibration Property not found in Object.create

} = 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,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<application
android:allowBackup="true"
Expand Down
39 changes: 39 additions & 0 deletions Libraries/Vibration/Vibration.js
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry didn't understand you 😞

*
* 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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not that easy to make vibration duration in ios. I would rather make separate pr for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicklockwood http://stackoverflow.com/a/13047464/1410905 if it is good solution I can make ios vibration duration here.

}
}
};

module.exports = Vibration;
5 changes: 5 additions & 0 deletions Libraries/Vibration/VibrationIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var RCTVibration = require('NativeModules').Vibration;
var invariant = require('fbjs/lib/invariant');

/**
* NOTE: `VibrationIOS` is being deprecated. Use `Vibration` instead.
*
* The Vibration API is exposed at `VibrationIOS.vibrate()`. On iOS, calling this
* function will trigger a one second vibration. The vibration is asynchronous
* so this method will return immediately.
Expand All @@ -27,6 +29,9 @@ var invariant = require('fbjs/lib/invariant');
*/

var VibrationIOS = {
/**
* @deprecated
*/
vibrate: function() {
invariant(
arguments[0] === undefined,
Expand Down
1 change: 1 addition & 0 deletions Libraries/react-native/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var ReactNative = {
get StyleSheet() { return require('StyleSheet'); },
get TimePickerAndroid() { return require('TimePickerAndroid'); },
get UIManager() { return require('UIManager'); },
get Vibration() { return require('Vibration'); },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update react-native.flow.js. It's a copy of this file for Flow as Flow doesn't understand getters well yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

get VibrationIOS() { return require('VibrationIOS'); },

// Plugins
Expand Down
1 change: 1 addition & 0 deletions Libraries/react-native/react-native.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var ReactNative = Object.assign(Object.create(require('react')), {
StyleSheet: require('StyleSheet'),
TimePickerAndroid: require('TimePickerAndroid'),
UIManager: require('UIManager'),
Vibration: require('Vibration'),
VibrationIOS: require('VibrationIOS'),

// Plugins
Expand Down
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',
)
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add the default license header stuff please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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);
}
}
}
1 change: 1 addition & 0 deletions ReactAndroid/src/main/java/com/facebook/react/shell/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ android_library(
react_native_target('java/com/facebook/react/views/viewpager:viewpager'),
react_native_target('java/com/facebook/react/views/webview:webview'),
react_native_target('java/com/facebook/react/modules/appstate:appstate'),
react_native_target('java/com/facebook/react/modules/vibration:vibration'),
react_native_target('java/com/facebook/react/modules/camera:camera'),
react_native_target('java/com/facebook/react/modules/clipboard:clipboard'),
react_native_target('java/com/facebook/react/modules/core:core'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.facebook.react.modules.storage.AsyncStorageModule;
import com.facebook.react.modules.timepicker.TimePickerDialogModule;
import com.facebook.react.modules.toast.ToastModule;
import com.facebook.react.modules.vibration.VibrationModule;
import com.facebook.react.modules.websocket.WebSocketModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.art.ARTRenderableViewManager;
Expand Down Expand Up @@ -81,6 +82,7 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
new StatusBarModule(reactContext),
new TimePickerDialogModule(reactContext),
new ToastModule(reactContext),
new VibrationModule(reactContext),
new WebSocketModule(reactContext)
);
}
Expand Down
1 change: 1 addition & 0 deletions website/server/extractDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ var apis = [
'../Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js',
'../Libraries/Components/ToastAndroid/ToastAndroid.android.js',
'../Libraries/Vibration/VibrationIOS.ios.js',
'../Libraries/Vibration/Vibration.js',
];

var stylesWithPermalink = [
Expand Down