question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] `onPress={Vibration.vibrate()}` doesn't do anything when button is pressed; only activates when the app is opened

See original GitHub issue

Description

I am re-opening this seemingly longstanding issue for some iOS devs (according to a few Google results): onPress={Vibration.vibrate()} does not do anything when the button is pressed in iOS 14/15, and no errors are thrown. Oddly, onPress={Vibration.vibrate()} does activate once immediately when I open the app, but never when I actually press the button. (Same exact behavior is seen with react-native-haptic-feedback’s library, except it emits haptic feedback instead of a vibration.)

I just spent a day and a half updating to XCode 13 and iOS 15.0.1 with the exact same results, to make sure I felt valid in submitting this issue. I just also created yet another brand new 0.66.0 React Native project with the same code as quoted below. Same results: Vibration.vibrate() is activated when the app opens, but absolutely nothing happens when I press the button (no logs either). It makes no difference whether I start the app with npx react-native run-ios --device or through Xcode, or with --configuration Release.

React Native version:

Xcode 13 | iOS 15.0.1 | RN 0.66.0 | macOS Big Sur 11.5.1 | iPhone 12

Steps To Reproduce

  1. npx react-native-cli init <repo name> (Uses latest RN 0.66.0)
  2. Run the code below through Xcode or npx react-native run-ios --device on iPhone iOS 14.8 or 15.0.1 (I have iPhone 12).
  3. Open the app. For me it vibrates upon opening the app, but does not vibrate when the button is pressed.

Expected Results

Phone vibrates when button is pressed

Snack, code example, screenshot, or link to a repository:

import React from 'react';
import {
  View,
  Button,
  Vibration
} from 'react-native';

const App = () => {

  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}} >
  <Button
    title="Buzz!"
    onPress={Vibration.vibrate()} />
    </View>
  );
};

export default App;

_Reference to old issue: https://github.com/facebook/react-native/issues/23404#issuecomment-934880420_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hb-webdevcommented, Oct 8, 2021

@tonkatsu-wallwisher - That’s how I have it written in my 0.64.2 app (which doesn’t work), but forgot to write it that way in my 0.66.0 sample code, sorry. Yes, that fixes it in the 0.66.0 app, thank you. But onPress={() => Vibration.vibrate()} still does not work in my 0.64.2 app. I suppose I need to update my 0.64.2 app to 0.66.0 now and test again.

0reactions
hb-webdevcommented, Oct 11, 2021

Updated to 0.66.0 and the button wasn’t vibrating still, but only on that particular screen.

Turns out I was unknowingly recording audio on that screen (with RNCamera), which disables iOS vibrations…So I just had to add this:

<RNCamera
    ...
    captureAudio={false} /* <--- Added this */
>
    <Button
        ...
        onPress={() => Vibration.vibrate()}
    />
</RNCamera>

😓 Sorry

Read more comments on GitHub >

github_iconTop Results From Across the Web

[iOS] Vibration.vibrate not working at all · Issue #23404 - GitHub
[iOS] onPress={Vibration.vibrate()} doesn't do anything when button is pressed; only activates when the app is opened #32352.
Read more >
Vibration - React Native
The vibrate() method can take a pattern argument with an array of numbers that represent time in milliseconds. You may set repeat to...
Read more >
Vibration Not Working on iPhone After iOS 16 ... - YouTube
iPhone not vibrating while on silent or otherwise, especially after iOS 16 update? In this video we will show you the best ways...
Read more >
Enable haptic Feedback on react-native touchable view
Clicking on android app button - make a sound and give the user an haptic Feedback. On the sound I saw that there...
Read more >
Haptic touch click noise - Apple Support Communities
The problem is that the clicks are LOUD. They do not respond to holding down the volume button either. This is separate from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found