-
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] Add support for vibration patterns #6400
Conversation
By analyzing the blame information on this pull request, we identified @skv-headless to be a potential reviewer. |
according to @satya164 note #6061 (comment) |
if (Platform.OS === 'android') { | ||
RCTVibration.vibrate(duration); | ||
if (typeof pattern === "number") { |
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.
quotes: Strings must use singlequote.
da2238b
to
47bedf1
Compare
@skv-headless updated the pull request. |
@satya164 could you please take a look? |
@skv-headless Hey, sorry, totally missed this. Will review tomorrow. Thanks for pinging me. |
@@ -27,11 +27,31 @@ var Platform = require('Platform'); | |||
*/ | |||
|
|||
var Vibration = { | |||
vibrate: function(duration: number = 400) { | |||
vibrate: function(pattern: number | Array<number> = 400, repeat: number) { |
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.
Can we mark repeat as optional? And maybe set the default value to 1?
Can the cancel method be supported on iOS? What'll happen if I do |
cc @dmmiller |
https://github.com/facebook/react-native/blob/master/Libraries/Vibration/RCTVibration.m#L20 |
47bedf1
to
6059488
Compare
@skv-headless updated the pull request. |
@@ -27,11 +27,31 @@ var Platform = require('Platform'); | |||
*/ | |||
|
|||
var Vibration = { | |||
vibrate: function(duration: number = 400) { | |||
vibrate: function(pattern: number | Array<number> = 400, repeat: number = -1) { |
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.
Why is the value of repeat -1? What happens when you set it to 0? Looks kinda weird to repeat something for -1 times.
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.
This is just a straight copy of Android (http://developer.android.com/reference/android/os/Vibrator.html#vibrate(long[], int))
That said, I tend to agree. I wonder if we should do just a boolean for repeat or not, and not allow for the direct indexing into the pattern for repeat.
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.
@dmmiller I think a number >= 0 is a reasonable API. 0 = don't repeat, n = repeat n times, of course we've to normalize the value to what Android understands.
In fact, the web vibration API doesn't have repeat option at all. I guess because it can be done using a loop and timeout, though not very convenient.
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.
@dmmiller Oh wait, it's the index of the pattern, not repeat n times. I think we should just change it to true | false
and pass 0 | -1
to Android accordingly.
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.
Yep, that was my point :)
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.
http://developer.android.com/intl/ru/reference/android/os/Vibrator.html#vibrate(long[], int)
repeat
the index into pattern at which to repeat, or -1 if you don't want to repeat.
true | false
is easier api but we will lose ability to repeat since exact index.
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.
@skv-headless I think it should be okay. Let's keep the Java code as it is, and change the JS to pass -1
or 0
. So that if we need it, we can change it in future, and think of a better API.
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. Not sure how to do it
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.
RCTVibration.vibrateByPattern(pattern, repeat ? 0 : -1);
6059488
to
dcf9cb8
Compare
@skv-headless updated the pull request. |
dcf9cb8
to
05fa913
Compare
@skv-headless updated the pull request. |
05fa913
to
1f9a309
Compare
@satya164 done |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
e20e8a3
Summary:and "not supported" warnings for ios Closes facebook#6400 Differential Revision: D3113988 fb-gh-sync-id: 169623f157ec59c38b4368cbc668c85201b67ed8 fbshipit-source-id: 169623f157ec59c38b4368cbc668c85201b67ed8
and "not supported" warnings for ios