Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ public void setClipboardData(@NonNull String text) {

@Override
public boolean clipboardHasStrings() {
CharSequence data =
PlatformPlugin.this.getClipboardData(
PlatformChannel.ClipboardContentFormat.PLAIN_TEXT);
return data != null && data.length() > 0;
return PlatformPlugin.this.clipboardHasText();
}
};

Expand Down Expand Up @@ -322,6 +319,12 @@ private void popSystemNavigator() {
}
}

private boolean clipboardHasText() {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
return clipboard.hasText();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried hasPrimaryClip but it completely wasn't working for me in the tests. It seemed to always return true, even if I setPrimaryClip to null or did clearPrimaryClip. You can see how I had it before in 72c32b8. CC @blasten who was helping me with this on Discord. Is that a robolectric problem?

}

private CharSequence getClipboardData(PlatformChannel.ClipboardContentFormat format) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ public void platformPlugin_hasStrings() {
clip = ClipData.newPlainText("", "");
clipboardManager.setPrimaryClip(clip);
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());

clip = ClipData.newPlainText("", null);
clipboardManager.setPrimaryClip(clip);
clipboardManager.clearPrimaryClip();
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());

clipboardManager.setPrimaryClip(null);
clipboardManager.clearPrimaryClip();
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());

clipboardManager.clearPrimaryClip();
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());
}

@Config(sdk = 29)
Expand Down