Commit 994a0de
authored
fix(rewards): share modal frozen on Android (#32183)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.
In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->
## **Description**
On Android, tapping **Refer a friend** on the Rewards referral screen
opened the native share sheet, but dismissing it could leave the app
unresponsive or crash entirely.
**Root cause:** `react-native-share`'s `Share.open()` uses
`startActivityForResult` on Android. When the share sheet closes, every
registered `ActivityEventListener` receives the result — including
`@metamask/react-native-payments`. That module forwards unknown request
codes to a deprecated `onActivityResult` overload that expects a
non-null `Intent`, which throws:
`NullPointerException: Parameter specified as non-null is null: method
BaseActivityEventListener.onActivityResult, parameter data`
**Fix:** Switch the referral share button to React Native's built-in
`Share.share()` (same pattern as `TokenDetails` and Predict share). RN's
share module uses `startActivity()` only, so it does not trigger the
payments module callback. The share call is also deferred with
`InteractionManager.runAfterInteractions()` so the button press gesture
completes before the native sheet opens.
- **Android:** subject + referral URL combined in `message` (Android
ignores the `url` field)
- **iOS:** separate `message` and `url` for rich link preview
- Errors are caught and logged via `Logger`
No dependency or native package patches required.
## **Changelog**
CHANGELOG entry: Fixed an Android crash and frozen UI after dismissing
the share sheet on the Rewards referral screen.
## **Related issues**
Refs: Internal QA — Android Rewards referral share sheet crash/freeze
## **Manual testing steps**
```gherkin
Feature: Rewards referral share on Android
Scenario: user shares a referral link without crashing
Given the user is subscribed to Rewards and on the Referrals screen
And a referral code has loaded
When the user taps "Refer a friend"
And the Android share sheet appears
And the user dismisses the share sheet without sharing
Then the app remains responsive (back navigation, scroll, and other taps work)
And the app does not crash
Scenario: user completes a share action
Given the user is on the Referrals screen with a referral code
When the user taps "Refer a friend"
And selects a share target (e.g. Messages or Copy)
Then the share completes without crashing
```
Also verified on iOS that the share sheet opens with message + URL and
dismisses normally.
## **Screenshots/Recordings**
N/A — crash/freeze repro is behavioral; manual QA on Android
device/emulator recommended.
### **Before**
App could freeze or crash after dismissing the share sheet.
### **After**
Share sheet dismisses cleanly; app stays interactive.
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### Performance checks (if applicable)
- [ ] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [ ] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
## Test plan
- [x] `yarn jest RewardsReferralView.test.tsx --coverage=false`
- [ ] Android: Referrals → Refer a friend → dismiss share sheet →
confirm no crash/freeze
- [ ] Android: Referrals → Refer a friend → share to an app → confirm no
crash
- [ ] iOS: Referrals → Refer a friend → dismiss and complete share →
confirm expected payloads
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Scoped Rewards referral UI change with no dependency or native
patches; it reduces Android activity-result side effects rather than
touching auth or payments code.
>
> **Overview**
> Fixes Android freeze/crash when users dismiss the Rewards **Refer a
friend** share sheet by stopping use of `react-native-share`'s
`Share.open()` (which routes through `startActivityForResult` and can
trip `@metamask/react-native-payments` with a null intent).
>
> Referral sharing now uses React Native's built-in **`Share.share()`**,
deferred with **`InteractionManager.runAfterInteractions()`** so the tap
gesture finishes before the sheet opens. **Android** gets subject + URL
in `message`; **iOS** keeps separate `message` and `url`. Failures are
logged via **`Logger`**.
>
> Tests mock `Share.share` and `InteractionManager`, assert
platform-specific payloads, and drop the `react-native-share` mock.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
5232d6e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent c83f25f commit 994a0de
2 files changed
Lines changed: 61 additions & 16 deletions
Lines changed: 42 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
88 | | - | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
| |||
104 | 118 | | |
105 | 119 | | |
106 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
| |||
207 | 225 | | |
208 | 226 | | |
209 | 227 | | |
210 | | - | |
| 228 | + | |
| 229 | + | |
211 | 230 | | |
212 | 231 | | |
213 | 232 | | |
214 | 233 | | |
215 | 234 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
221 | 253 | | |
222 | 254 | | |
223 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| |||
0 commit comments