Skip to content
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

Closed

Conversation

skv-headless
Copy link
Contributor

and "not supported" warnings for ios

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @skv-headless to be a potential reviewer.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Mar 10, 2016
@skv-headless
Copy link
Contributor Author

according to @satya164 note #6061 (comment)

if (Platform.OS === 'android') {
RCTVibration.vibrate(duration);
if (typeof pattern === "number") {

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.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

@satya164 could you please take a look?

@satya164
Copy link
Contributor

@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) {
Copy link
Contributor

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?

@satya164
Copy link
Contributor

Can the cancel method be supported on iOS? What'll happen if I do Vibration.vibrate(0) when a vibration is in progress?

@satya164
Copy link
Contributor

cc @dmmiller

@skv-headless
Copy link
Contributor Author

https://github.com/facebook/react-native/blob/master/Libraries/Vibration/RCTVibration.m#L20
ios implementation and I don't see way to stop vibration.

@facebook-github-bot
Copy link
Contributor

@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) {
Copy link
Contributor

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.

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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. Not sure how to do it

Copy link
Contributor

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);

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

@satya164 done

@satya164 satya164 changed the title [Android] vibration patterns with examples [Android] Add support for vibration patterns Mar 30, 2016
@satya164
Copy link
Contributor

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in e20e8a3 Mar 30, 2016
zebulgar pushed a commit to nightingale/react-native that referenced this pull request Jun 18, 2016
Summary:and "not supported" warnings for ios
Closes facebook#6400

Differential Revision: D3113988

fb-gh-sync-id: 169623f157ec59c38b4368cbc668c85201b67ed8
fbshipit-source-id: 169623f157ec59c38b4368cbc668c85201b67ed8
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants