mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 22:43:10 +08:00
vibration module
Summary:I will fix other notes from https://github.com/facebook/react-native/pull/2794 if I get positive feedback. Closes https://github.com/facebook/react-native/pull/6061 Reviewed By: nicklockwood Differential Revision: D2982173 Pulled By: dmmiller fb-gh-sync-id: d1e9407798b0293b090897a10996085b0f0c1b3e shipit-source-id: d1e9407798b0293b090897a10996085b0f0c1b3e
This commit is contained in:
committed by
Facebook Github Bot 7
parent
d2d00e0fcd
commit
1bab7c5182
@@ -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',
|
||||
)
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.facebook.react.modules.statusbar.StatusBarModule;
|
||||
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;
|
||||
@@ -81,6 +82,7 @@ public class MainReactPackage implements ReactPackage {
|
||||
new StatusBarModule(reactContext),
|
||||
new TimePickerDialogModule(reactContext),
|
||||
new ToastModule(reactContext),
|
||||
new VibrationModule(reactContext),
|
||||
new WebSocketModule(reactContext)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user