-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] vibration module #6061
Conversation
By analyzing the blame information on this pull request, we identified @mkonicek, @nicklockwood and @vjeux to be potential reviewers. |
60216b1
to
2964c4b
Compare
*/ | ||
|
||
var Vibration = { | ||
vibrate: function(duration=400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter duration
Missing annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter duration
Missing annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Flow to declare it's a number.
Cc: @dmmiller |
* function will trigger a one second vibration. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: e.g.
There was a problem hiding this comment.
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 😞
Looks good overall, thanks! |
2964c4b
to
536053e
Compare
@skv-headless updated the pull request. |
|
||
var RCTVibration = require('NativeModules').Vibration; | ||
|
||
var invariant = require('invariant'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no-unused-vars: "invariant" is defined but never used
536053e
to
0f27881
Compare
@skv-headless updated the pull request. |
4136394
to
f7eb974
Compare
@skv-headless updated the pull request. |
if (Platform.OS === 'android') { | ||
RCTVibration.vibrate(duration); | ||
} else { | ||
RCTVibration.vibrate(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
f7eb974
to
5aff712
Compare
@skv-headless updated the pull request. |
import com.facebook.react.bridge.ReactMethod; | ||
|
||
public class VibrationModule extends ReactContextBaseJavaModule { | ||
ReactApplicationContext reactContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to store this separately. It is available on ReactContextBaseJavaModule via getReactApplicationContext()
Can we also add comments about deprecating VibrationIOS since we will now just have one Vibration API? |
Since we're adding this, it would be great to support a vibration pattern. Seems pretty simple to implement - http://developer.android.com/reference/android/os/Vibrator.html |
5aff712
to
46208a2
Compare
@skv-headless updated the pull request. |
@dmmiller I've fixed your notes. |
@skv-headless Feel free to do it in a follow-up PR :D |
46208a2
to
5d2bf34
Compare
@skv-headless updated the pull request. |
I think this PR is finished. I've already started to work on vibration patters but I'm going to create separate PR for that. |
@facebook-github-bot shipit |
Cool, thanks. I've asked for the bot to accept it :) |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
Failed to land because of failing tests. Luckily this should be easy, you just need to update BUCK files so that the code builds internally at fb where we use Buck. See https://circleci.com/gh/facebook/react-native/3133 My guess is you just need to add a dependency here: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK |
@mkonicek is there any instruction how to launch tests locally? I'll update tomorrow. |
@skv-headless updated the pull request. |
1c90bcd
to
e48feda
Compare
@skv-headless updated the pull request. |
@mkonicek circle tests passed |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
@dmmiller if there are problems with shipping (maybe like this #6208 (comment)) I can create PR again |
I'll get it to land. Let me commandeer the diff locally and get it in. |
@facebook-github-bot shipit |
1bab7c5
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
Summary: This is a revised follow up version from #8574 ( originally implemented in `objc` ) This PR change the implementation in JS suggested by javache **motivation** To supports vibration pattern like android. The [iOS vibration implementation link](http://stackoverflow.com/questions/12966467/are-there-apis-for-custom-vibrations-in-ios/13047464#13047464) mentioned by skv-headless at #6061 (comment), which will not be accepted by apple since that implementation uses a private API. Thus, I use pure public API `NSTimer` to implement it. **Note** Since vibration time on iOS is not configurable, there are slightly differences with android. for example: **Android Usage:** `Vibration.vibrate([0, 500, 200, 500])` ==> V(0.5s) --wait(0.2s)--> V(0.5s) `Vibration.vibrate([300, 500, 200, 500])` ==> --wait(0.3s)--> V(0.5s) --wait(0.2s)--> V(0.5s) **iOS Usage:** if first argument is 0, it will not be included in pattern array. ( vibration Closes #9233 Differential Revision: D3775085 Pulled By: javache fbshipit-source-id: 370495857d5581399de32d2bed1ea1bcce193e9d
Summary: This is a revised follow up version from #8574 ( originally implemented in `objc` ) This PR change the implementation in JS suggested by javache **motivation** To supports vibration pattern like android. The [iOS vibration implementation link](http://stackoverflow.com/questions/12966467/are-there-apis-for-custom-vibrations-in-ios/13047464#13047464) mentioned by skv-headless at facebook/react-native#6061 (comment), which will not be accepted by apple since that implementation uses a private API. Thus, I use pure public API `NSTimer` to implement it. **Note** Since vibration time on iOS is not configurable, there are slightly differences with android. for example: **Android Usage:** `Vibration.vibrate([0, 500, 200, 500])` ==> V(0.5s) --wait(0.2s)--> V(0.5s) `Vibration.vibrate([300, 500, 200, 500])` ==> --wait(0.3s)--> V(0.5s) --wait(0.2s)--> V(0.5s) **iOS Usage:** if first argument is 0, it will not be included in pattern array. ( vibration Closes facebook/react-native#9233 Differential Revision: D3775085 Pulled By: javache fbshipit-source-id: 370495857d5581399de32d2bed1ea1bcce193e9d
I will fix other notes from #2794 if I get positive feedback.