UNPKG

1.16 kBPlain TextView Raw
1/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#import "RCTClipboard.h"
9
10#import <FBReactNativeSpec/FBReactNativeSpec.h>
11#import <UIKit/UIKit.h>
12
13#import "CoreModulesPlugins.h"
14
15using namespace facebook::react;
16
17@interface RCTClipboard () <NativeClipboardSpec>
18@end
19
20@implementation RCTClipboard
21
22RCT_EXPORT_MODULE()
23
24- (dispatch_queue_t)methodQueue
25{
26 return dispatch_get_main_queue();
27}
28
29
30RCT_EXPORT_METHOD(setString:(NSString *)content)
31{
32 UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
33 clipboard.string = (content ? : @"");
34}
35
36RCT_EXPORT_METHOD(getString:(RCTPromiseResolveBlock)resolve
37 reject:(__unused RCTPromiseRejectBlock)reject)
38{
39 UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
40 resolve((clipboard.string ? : @""));
41}
42
43- (std::shared_ptr<TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<CallInvoker>)jsInvoker
44{
45 return std::make_shared<NativeClipboardSpecJSI>(self, jsInvoker);
46}
47
48@end
49
50Class RCTClipboardCls(void) {
51 return RCTClipboard.class;
52}