File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed
plugins/clipboard-manager Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " clipboard-manager " : " minor"
3
+ ---
4
+
5
+ Add support for clearing clipboard text on iOS and Android.
Original file line number Diff line number Diff line change @@ -92,7 +92,11 @@ class ClipboardPlugin(private val activity: Activity) : Plugin(activity) {
92
92
val clipData = when (args) {
93
93
is WriteOptions .PlainText -> {
94
94
ClipData .newPlainText(args.label, args.text)
95
+ } else -> {
96
+ invoke.reject(" Invalid write options provided" )
97
+ return
95
98
}
99
+
96
100
}
97
101
98
102
manager.setPrimaryClip(clipData)
@@ -120,4 +124,12 @@ class ClipboardPlugin(private val activity: Activity) : Plugin(activity) {
120
124
121
125
invoke.resolveObject(data)
122
126
}
127
+
128
+ @Command
129
+ fun clear (invoke : Invoke ) {
130
+ if (manager.hasPrimaryClip()) {
131
+ manager.clearPrimaryClip()
132
+ }
133
+ invoke.resolve()
134
+ }
123
135
}
Original file line number Diff line number Diff line change @@ -38,6 +38,12 @@ class ClipboardPlugin: Plugin {
38
38
invoke. reject ( " Clipboard is empty " )
39
39
}
40
40
}
41
+
42
+ @objc public func clear( _ invoke: Invoke ) throws {
43
+ let clipboard = UIPasteboard . general
44
+ clipboard. items = [ ]
45
+ invoke. resolve ( )
46
+ }
41
47
}
42
48
43
49
@_cdecl ( " init_plugin_clipboard " )
Original file line number Diff line number Diff line change @@ -92,9 +92,7 @@ impl<R: Runtime> Clipboard<R> {
92
92
}
93
93
94
94
pub fn clear ( & self ) -> crate :: Result < ( ) > {
95
- Err ( crate :: Error :: Clipboard (
96
- "Unsupported on this platform" . to_string ( ) ,
97
- ) )
95
+ self . 0 . run_mobile_plugin ( "clear" , ( ) ) . map_err ( Into :: into)
98
96
}
99
97
}
100
98
You can’t perform that action at this time.
0 commit comments