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] vibration module #6061

Closed
wants to merge 2 commits into from

Conversation

skv-headless
Copy link
Contributor

I will fix other notes from #2794 if I get positive feedback.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @nicklockwood and @vjeux to be potential reviewers.

@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 Feb 21, 2016
*/

var Vibration = {
vibrate: function(duration=400) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter duration Missing annotation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter duration Missing annotation

Copy link
Contributor

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.

@nicklockwood
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: e.g.

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 didn't understand you 😞

@mkonicek
Copy link
Contributor

Looks good overall, thanks!

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.


var RCTVibration = require('NativeModules').Vibration;

var invariant = require('invariant');

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

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

if (Platform.OS === 'android') {
RCTVibration.vibrate(duration);
} else {
RCTVibration.vibrate();
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

import com.facebook.react.bridge.ReactMethod;

public class VibrationModule extends ReactContextBaseJavaModule {
ReactApplicationContext reactContext;

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

@dmmiller
Copy link

Can we also add comments about deprecating VibrationIOS since we will now just have one Vibration API?

@satya164
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

@dmmiller I've fixed your notes.

@satya164
Copy link
Contributor

@skv-headless Feel free to do it in a follow-up PR :D

@facebook-github-bot
Copy link
Contributor

@skv-headless updated the pull request.

@skv-headless
Copy link
Contributor Author

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.

@dmmiller
Copy link

@facebook-github-bot shipit

@dmmiller
Copy link

Cool, thanks. I've asked for the bot to accept it :)

@bestander
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.

@mkonicek
Copy link
Contributor

mkonicek commented Mar 1, 2016

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

@skv-headless
Copy link
Contributor Author

@mkonicek is there any instruction how to launch tests locally? I'll update tomorrow.

@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

@mkonicek circle tests passed

@dmmiller
Copy link

dmmiller commented Mar 2, 2016

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

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

@skv-headless
Copy link
Contributor Author

@dmmiller if there are problems with shipping (maybe like this #6208 (comment)) I can create PR again

@dmmiller
Copy link

dmmiller commented Mar 3, 2016

I'll get it to land. Let me commandeer the diff locally and get it in.

@dmmiller
Copy link

dmmiller commented Mar 3, 2016

@facebook-github-bot shipit

@ghost ghost closed this in 1bab7c5 Mar 3, 2016
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
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
ghost pushed a commit that referenced this pull request Aug 26, 2016
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
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Sep 14, 2016
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
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.

8 participants