feat(feedback): Show feedback widget on device shake#5754
Draft
feat(feedback): Show feedback widget on device shake#5754
Conversation
Implement device shake detection to trigger the feedback widget.
No permissions are required on either platform:
- iOS: Uses UIKit's motionEnded:withEvent: via UIWindow swizzle
- Android: Uses SensorManager accelerometer (TYPE_ACCELEROMETER)
Public API:
- showFeedbackOnShake() / hideFeedbackOnShake() imperative APIs
- feedbackIntegration({ enableShakeToReport: true }) declarative option
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion.sendEvent: The previous implementation swizzled UIWindow.motionEnded:withEvent: which was intercepted by React Native's dev menu before our handler could fire. Switching to UIApplication.sendEvent: intercepts events before the responder chain, so shake events are detected even when RN dev menu or another responder consumes the motion event without calling super. Added a 1-second cooldown to prevent double-firing since both motionBegan and motionEnded trigger UIEventSubtypeMotionShake.
…wizzle UIApplication.sendEvent: is not invoked by the iOS simulator for the simulated shake (Cmd+Ctrl+Z); it goes directly through UIWindow.motionEnded:withEvent: instead. React Native's dev menu swizzles UIWindow.motionEnded:withEvent: at bridge load time. Because we swizzle from startObserving (triggered by componentDidMount via NativeEventEmitter.addListener), our swizzle always runs after RN's — making sentry_motionEnded the outermost layer that calls through to RN's dev-menu handler via the stored original IMP. This approach works on both real devices and the iOS simulator.
Without FeedbackWidgetProvider rendered in the tree, componentDidMount never fires, startShakeListener is never called, and the native swizzle is never set up — so shake-to-report has no effect despite enableShakeToReport: true being configured on the integration.
…le app" This reverts commit 6054e19.
Instead of relying on startObserving (which fires for any event type on the module's first listener), mirror the Android approach: override addListener and explicitly call [RNSentryShakeDetector enable] when the shake event is subscribed to. This ensures the UIWindow swizzle is set up reliably regardless of listener ordering or TurboModule event-emitter behaviour.
Without this import SentryDefines.h is never included, SENTRY_HAS_UIKIT evaluates to 0, and the entire shake detector implementation is compiled out leaving only the no-op stubs. All other files in the module that use SENTRY_HAS_UIKIT (RNSentryOnDrawReporter.m, RNSentryDependencyContainer.m, etc.) include @import Sentry for exactly this reason.
@import Sentry caused a startup crash. Replace both the module import and SENTRY_HAS_UIKIT guard with TARGET_OS_IOS which has identical semantics for shake detection (iOS only) and needs no external import.
…eport On iOS with New Architecture (TurboModules), NativeEventEmitter.addListener does not dispatch to native addListener:, so the UIWindow swizzle for shake detection was never enabled. Adds explicit enableShakeDetection/disableShakeDetection RCT_EXPORT_METHODs on iOS and no-op stubs on Android. JS startShakeListener now calls enableShakeDetection directly after subscribing to the event, bypassing the unreliable NativeEventEmitter → native dispatch path on iOS. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
UIWindow inherits motionEnded:withEvent: from UIResponder and may not have its own implementation. Using method_setImplementation directly on the inherited Method would modify UIResponder, affecting all subclasses and causing a doesNotRecognizeSelector crash. Fix by calling class_addMethod first to ensure UIWindow has its own method before replacing the IMP. Also prevent duplicate NSNotification observers on component remount, and clean up debug logging. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… native SDKs Remove the RN-specific shake detector implementations and delegate to SentryShakeDetector (iOS: sentry-cocoa, Android: sentry-android-core) so the implementation is shared with other SDKs that have feedback UI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- Show feedback widget on device shake ([#5754](https://github.com/getsentry/sentry-react-native/pull/5754))If none of the above apply, you can opt out of this check by adding |
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
Plus 6 more 🤖 This preview updates automatically when you update the PR. |
This was referenced Mar 4, 2026
7 tasks
antonis
commented
Mar 4, 2026
Contributor
Author
antonis
left a comment
There was a problem hiding this comment.
Marking as blocked till the native PRs are merged
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
Implements shake-to-report for the feedback widget and delegates shake detection to the implementations in the native SDKs:
SentryShakeDetectorfrom sentry-cocoa (feat(feedback): implement shake gesture detection sentry-cocoa#7579)SentryShakeDetectorfrom sentry-android-core (feat(feedback): implement shake gesture detection sentry-java#5150)The
RNSentry.mmnow imports<Sentry/SentryShakeDetector.h>and usesSentryShakeDetectedNotificationinstead of the RN-specific ones. On Android,RNSentryModuleImplusesio.sentry.android.core.SentryShakeDetector.💡 Motivation and Context
Users have requested a way to trigger the feedback widget by shaking the device, without the need for a visible button. This is a common UX pattern for in-app feedback
Fixes #4735
This PR depends on the two native SDK PRs above merging first.
💚 How did you test it?
yarn build,yarn test,yarn lint,yarn circularDepCheck📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
Merge the native SDK PRs, update the Cocoa/Java dependency versions in the RN SDK, then merge this PR.