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

feat: Expose hasString method for iOS 14+ #73

Merged
merged 3 commits into from
Oct 12, 2020

Conversation

gnardini
Copy link
Contributor

Firstly, thanks for the work on the clipboard!

Overview

iOS 14 now shows a notification each time an app accesses the clipboard, so we need to be more careful on when to read it. It also has a new API that allows apps to tell if there's any content on the clipboard or not. The API has more methods than the one I implemented, I just added the one I needed. I don't have time to keep working on this unfortunately to add the rest of the methods :( I understand if you think this is not enough to merge.

Test Plan

Unfortunately, the example project didn't compile for me, so I couldn't use that one to test, I tested directly on my own project.
To test you need an iOS 14 device and one with an older version. On both of them add a call somewhere to await Clipboard.hasString(). Do so while having content on the clipboard and while having an empty clipboard. You could print the result of the call to console.log or any other logger to see that the correct value is returned.

RCT_EXPORT_METHOD(hasString:(RCTPromiseResolveBlock)resolve
reject:(__unused RCTPromiseRejectBlock)reject)
{
bool stringPresent = false;

Choose a reason for hiding this comment

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

nit: BOOL should be preferred in ObjC, with YES or NO as values.

See https://stackoverflow.com/questions/541289/objective-c-bool-vs-bool

stringPresent = clipboard.hasStrings;
} else {
NSString* stringInPasteboard = clipboard.string;
stringPresent = stringInPasteboard != nil;

Choose a reason for hiding this comment

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

Can it be empty too?

@filiptronicek
Copy link

Awesome! Can we implement stuff from #64 also?

Copy link
Member

@Naturalclar Naturalclar left a comment

Choose a reason for hiding this comment

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

@gnardini amazing! tested on example app and seems to be working great.
sorry for the example project on this repo not working for you, there was a typo in podfile which was preventing the example to work, but now it's fixed.

@Naturalclar Naturalclar merged commit a83fce8 into react-native-clipboard:master Oct 12, 2020
@barrymcgee
Copy link

barrymcgee commented Dec 1, 2021

I'm finding that await Clipboard.hasString() always returns as true even after running pbcopy < /dev/null - is this expected?

#125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants