-
-
Notifications
You must be signed in to change notification settings - Fork 359
feat(feedback): Show feedback widget on device shake #5754
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
Open
antonis
wants to merge
35
commits into
main
Choose a base branch
from
antonis/feedback-shake-native
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+476
−11
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
9bc0c17
feat(feedback): Show feedback widget on device shake
antonis c5d398e
Add to sample app
antonis 3cb51f5
Merge branch 'main' into antonis/feedback-shake
antonis 3e37fe4
Merge branch 'main' into antonis/feedback-shake
antonis 5271319
Merge branch 'main' into antonis/feedback-shake
antonis 96664e8
fix(ios): fix shake detection in iOS simulator by swizzling UIApplica…
antonis 58b9f2b
Merge branch 'main' into antonis/feedback-shake
antonis a027843
fix(ios): switch shake detection to UIWindow.motionEnded:withEvent: s…
antonis 6054e19
test(sample): add FeedbackWidgetProvider to React Native sample app
antonis 6d13f6a
Revert "test(sample): add FeedbackWidgetProvider to React Native samp…
antonis bf89f61
fix(ios): explicitly enable shake detection in addListener like Android
antonis 128bd3e
debug(ios): add NSLog tracing to shake detection chain
antonis db0e082
Merge branch 'main' into antonis/feedback-shake
antonis ea484a2
Merge branch 'main' into antonis/feedback-shake
antonis 5cb9033
fix(ios): add @import Sentry so SENTRY_HAS_UIKIT is defined
antonis 023bab7
fix(ios): use TARGET_OS_IOS instead of SENTRY_HAS_UIKIT
antonis 3e473ae
Merge branch 'main' into antonis/feedback-shake
antonis e844405
fix(ios): use explicit enableShakeDetection method for iOS shake-to-r…
antonis d725799
fix(ios): fix shake detection crash and swizzle safety
antonis 5c048e0
Merge branch 'main' into antonis/feedback-shake
antonis 27867aa
refactor: replace RNSentryShakeDetector with SentryShakeDetector from…
antonis daf949d
Merge branch 'main' into antonis/feedback-shake-native
antonis 59d3752
Merge branch 'main' into antonis/feedback-shake-native
antonis 725ceaf
fix(ios): adapt to SentryShakeDetector refactored to Swift in sentry-…
antonis 04c1bd4
Merge branch 'main' into antonis/feedback-shake-native
antonis 8c44ee5
Reverse unneeded objc changes
antonis fcdc83c
Reverse obj change
antonis cfcb5c7
Rename methods for clarity
antonis 33a5918
fix(android,ios): Fix shake detection lifecycle bugs
antonis a7b836f
Update changelog
antonis 259687a
fix(ios): Use dedicated flag for shake event emission
antonis 6a1db5e
fix(feedback): Guard against shake listener crashes and asymmetric li…
antonis f88f95c
fix(feedback): Remove subscription on shake listener start failure
antonis ca15aff
fix(android): Wrap shake detection in try/catch to prevent host app c…
antonis bc93b34
fix(feedback): Prevent provider from stopping externally-owned shake …
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| extern NSString *const RNSentryNewFrameEvent; | ||
| extern NSString *const RNSentryOnShakeEvent; | ||
| extern NSString *const RNSentryNativeLogEvent; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #import "RNSentryEvents.h" | ||
|
|
||
| NSString *const RNSentryNewFrameEvent = @"rn_sentry_new_frame"; | ||
| NSString *const RNSentryOnShakeEvent = @"rn_sentry_on_shake"; | ||
| NSString *const RNSentryNativeLogEvent = @"SentryNativeLog"; |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { debug } from '@sentry/core'; | ||
| import type { EmitterSubscription, NativeModule } from 'react-native'; | ||
| import { NativeEventEmitter } from 'react-native'; | ||
| import { isWeb } from '../utils/environment'; | ||
| import { getRNSentryModule } from '../wrapper'; | ||
|
|
||
| export const OnShakeEventName = 'rn_sentry_on_shake'; | ||
|
|
||
| let _shakeSubscription: EmitterSubscription | null = null; | ||
|
|
||
| /** | ||
| * Creates a NativeEventEmitter for the given module. | ||
| * Can be overridden in tests via the `createEmitter` parameter. | ||
| */ | ||
| type EmitterFactory = (nativeModule: NativeModule) => NativeEventEmitter; | ||
|
|
||
| const defaultEmitterFactory: EmitterFactory = nativeModule => new NativeEventEmitter(nativeModule); | ||
|
|
||
| /** | ||
| * Starts listening for device shake events and invokes the provided callback when a shake is detected. | ||
| * | ||
| * This starts native shake detection: | ||
| * - iOS: Uses UIKit's motion event detection (no permissions required) | ||
| * - Android: Uses the accelerometer sensor (no permissions required) | ||
| */ | ||
| export function startShakeListener(onShake: () => void, createEmitter: EmitterFactory = defaultEmitterFactory): boolean { | ||
| if (_shakeSubscription) { | ||
| return false; | ||
| } | ||
|
|
||
| if (isWeb()) { | ||
| debug.warn('Shake detection is not supported on Web.'); | ||
| return false; | ||
| } | ||
|
|
||
| const nativeModule = getRNSentryModule() as NativeModule | undefined; | ||
| if (!nativeModule) { | ||
| debug.warn('Native module is not available. Shake detection will not work.'); | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| const emitter = createEmitter(nativeModule); | ||
| _shakeSubscription = emitter.addListener(OnShakeEventName, () => { | ||
| onShake(); | ||
| }); | ||
|
|
||
| // Explicitly enable native shake detection. On iOS with New Architecture (TurboModules), | ||
| // NativeEventEmitter.addListener does not dispatch to native addListener:, so the | ||
| // native shake listener would never start without this explicit call. | ||
| const module = nativeModule as { enableShakeDetection?: () => void }; | ||
| if (module.enableShakeDetection) { | ||
| module.enableShakeDetection(); | ||
| } else { | ||
| debug.warn('enableShakeDetection is not available on the native module.'); | ||
| } | ||
| return true; | ||
| } catch (e) { | ||
| debug.warn('Failed to start shake listener:', e); | ||
| if (_shakeSubscription) { | ||
| _shakeSubscription.remove(); | ||
| _shakeSubscription = null; | ||
| } | ||
| return false; | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Stops listening for device shake events. | ||
| */ | ||
| export function stopShakeListener(): void { | ||
| if (_shakeSubscription) { | ||
| _shakeSubscription.remove(); | ||
| _shakeSubscription = null; | ||
|
|
||
| const nativeModule = getRNSentryModule() as { disableShakeDetection?: () => void } | undefined; | ||
| nativeModule?.disableShakeDetection?.(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether the shake listener is currently active. | ||
| * Exported for testing purposes. | ||
| */ | ||
| export function isShakeListenerActive(): boolean { | ||
| return _shakeSubscription !== null; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.