Skip to content
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

[clipboard][Android] Fixes clipboard listener is called twice #19723

Merged

Conversation

lukmccall
Copy link
Contributor

Why

Fixes clipboard listener is called twice on Android.
Fixes clipboard listener crashing the application on Android during the initialization phase.

How

During the dev-client QA, I faced two issues with a clipboard. First of all, the listener's called twice for a single event. It was fixed by checking the timestamp. Moreover, the clipboard code may break the application, when the same listener is called in the initialization phase when react modules aren't fully initiated. I've decided to add a function to the app context to check if the react native is alive.

Test Plan

  • bare-expo ✅

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Oct 27, 2022
Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me but wondering why there're duplicated events from native.

@Kudo
Copy link
Contributor

Kudo commented Oct 27, 2022

android unit test is failed at

expo.modules.clipboard.ClipboardModuleTest > should emit events when clipboard changes FAILED
    java.lang.AssertionError at ClipboardModuleTest.kt:133

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@lukmccall lukmccall merged commit 5c6007e into main Oct 28, 2022
@lukmccall lukmccall deleted the @lukmccall/clipboard/fix-clipboard-listener-is-called-twice branch October 28, 2022 08:44
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Oct 28, 2022
lukmccall added a commit that referenced this pull request Oct 28, 2022
lukmccall added a commit that referenced this pull request Oct 28, 2022
# Why

Backports #19723 and #19725 to sdk-47 versioned code.
lukmccall pushed a commit that referenced this pull request Mar 1, 2023
… <26 (#21383)

# Why

On devices with Android versions below 8 (SDK 26), the changes in #19723 causes the app to crash whenever a string is copied due to using the `getTimestamp()` function that is only available on SDK 26 and above: https://developer.android.com/reference/android/content/ClipDescription#getTimestamp()

# How

Add a check to ensure `Build.VERSION.SDK_INT >= Build.VERSION_CODES.O` before calling `clip.timestamp`.

# Test Plan

Ran `yarn android` in `apps/bare-expo`
Kudo pushed a commit that referenced this pull request Mar 3, 2023
… <26 (#21383)

# Why

On devices with Android versions below 8 (SDK 26), the changes in #19723 causes the app to crash whenever a string is copied due to using the `getTimestamp()` function that is only available on SDK 26 and above: https://developer.android.com/reference/android/content/ClipDescription#getTimestamp()

# How

Add a check to ensure `Build.VERSION.SDK_INT >= Build.VERSION_CODES.O` before calling `clip.timestamp`.

# Test Plan

Ran `yarn android` in `apps/bare-expo`

(cherry picked from commit 1ef1f8a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants