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: add copy to clipboard #3

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 @@ -93,4 +93,8 @@ class VgsAttrInstance(context: ReactContext) : LinearLayout(context) {

this.vgsShow.requestAsync(request.build());
}

fun copyToClipboard() {
vgsText.copyToClipboard()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class VgsShowReactNativeViewManager : SimpleViewManager<View>() {
args.getString(2) as String,
args.getMap(3) as ReadableMap
)
"copyToClipboard" -> (view as VgsAttrInstance).copyToClipboard()
}
}

Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ PODS:
- React-Core (= 0.63.4)
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- vgs-show-react-native (0.1.0):
- vgs-show-react-native (0.1.2):
- React-Core
- VGSShowSDK
- VGSShowSDK (1.0.4):
Expand Down Expand Up @@ -474,11 +474,11 @@ SPEC CHECKSUMS:
React-RCTText: 5c51df3f08cb9dedc6e790161195d12bac06101c
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
vgs-show-react-native: 6a2bc9ccc1acc7411f1a8a8e3034b839e22fb21e
vgs-show-react-native: feaef73c7c6561b2e4a2dff2cc7b22174422ea19
VGSShowSDK: 82d8c1c1d1e3cf32c81b26057f7e7aaa20f91cfc
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 22d1aef0643c7abb6f0d30de17ef3ea0b598764c

COCOAPODS: 1.10.1
COCOAPODS: 1.10.2
2 changes: 2 additions & 0 deletions ios/VgsShowReactNativeViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ @interface RCT_EXTERN_MODULE(VgsShowReactNativeViewManager, RCTViewManager)
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(copyToClipboard:(nonnull NSNumber *)node)

@end
16 changes: 16 additions & 0 deletions ios/VgsShowReactNativeViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class VgsShowReactNativeViewManager: RCTViewManager {
component.revealData(path: path, method: method, payload: payload, resolve: resolve, reject: reject)
}
}

@objc(copyToClipboard) func copyToClipboard(_ node: NSNumber) {
DispatchQueue.main.async {
let component = self.bridge.uiManager.view(
forReactTag: node
) as! VgsShowReactNativeView
component.copyToClipboard()
}
}
}

class VgsShowReactNativeView : UIView, VGSLabelDelegate {
Expand Down Expand Up @@ -170,6 +179,13 @@ class VgsShowReactNativeView : UIView, VGSLabelDelegate {
}
}
}

@objc func copyToClipboard() {
if (attributeLabel == nil) {
return;
}
attributeLabel.copyTextToClipboard(format: .raw)
}

func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
Expand Down
17 changes: 17 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ export class VgsShowAttribute extends React.Component<VgsShowReactNativeProps> {
return Promise.reject('No ref available for native comp!');
}

copyToClipboard(): void {
const handle = findNodeHandle(this._nativeRef);
const copy = Platform.select({
ios: () => {
NativeModules.VgsShowReactNativeViewManager.copyToClipboard(handle);
},
android: () => {
UIManager.dispatchViewManagerCommand(
handle,
'copyToClipboard' as any,
[]
);
},
});
copy?.();
}

render() {
return (
<VgsShowAttributeNative
Expand Down