mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 22:38:37 +08:00
Add support for vibration patterns
Summary:and "not supported" warnings for ios Closes https://github.com/facebook/react-native/pull/6400 Differential Revision: D3113988 fb-gh-sync-id: 169623f157ec59c38b4368cbc668c85201b67ed8 fbshipit-source-id: 169623f157ec59c38b4368cbc668c85201b67ed8
This commit is contained in:
committed by
Facebook Github Bot 0
parent
2bcf4bef2b
commit
e20e8a3cc8
@@ -15,6 +15,7 @@ import android.os.Vibrator;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
|
||||
public class VibrationModule extends ReactContextBaseJavaModule {
|
||||
|
||||
@@ -34,4 +35,25 @@ public class VibrationModule extends ReactContextBaseJavaModule {
|
||||
v.vibrate(duration);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void vibrateByPattern(ReadableArray pattern, int repeat) {
|
||||
long[] patternLong = new long[pattern.size()];
|
||||
for (int i = 0; i < pattern.size(); i++) {
|
||||
patternLong[i] = pattern.getInt(i);
|
||||
}
|
||||
|
||||
Vibrator v = (Vibrator) getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (v != null) {
|
||||
v.vibrate(patternLong, repeat);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void cancel() {
|
||||
Vibrator v = (Vibrator) getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (v != null) {
|
||||
v.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user