[iOS] `onPress={Vibration.vibrate()}` doesn't do anything when button is pressed; only activates when the app is opened
See original GitHub issueDescription
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
npx react-native-cli init <repo name>
(Uses latest RN 0.66.0)- 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). - 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:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
@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.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:😓 Sorry