@thiagobueno/rn-selectable-text 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/SelectableTextView.mm +25 -3
- package/package.json +2 -2
|
@@ -18,10 +18,21 @@ using namespace facebook::react;
|
|
|
18
18
|
|
|
19
19
|
@implementation SelectableUITextView
|
|
20
20
|
|
|
21
|
+
- (void)didMoveToWindow {
|
|
22
|
+
[super didMoveToWindow];
|
|
23
|
+
// FIX: iOS 16+ text selection bug after navigation.
|
|
24
|
+
// When returning to the screen, we force iOS to re-evaluate the interaction state.
|
|
25
|
+
if (self.window) {
|
|
26
|
+
BOOL wasSelectable = self.selectable;
|
|
27
|
+
self.selectable = NO;
|
|
28
|
+
self.selectable = wasSelectable;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
|
22
33
|
{
|
|
23
34
|
// FIX: We explicitly tell iOS that we can perform standard actions.
|
|
24
|
-
// This prevents the "[UIKitCore] The edit menu did not have performable commands" warning
|
|
35
|
+
// This prevents the "[UIKitCore] The edit menu did not have performable commands" warning.
|
|
25
36
|
if (action == @selector(copy:) || action == @selector(selectAll:)) {
|
|
26
37
|
return YES;
|
|
27
38
|
}
|
|
@@ -131,13 +142,19 @@ using namespace facebook::react;
|
|
|
131
142
|
- (void)prepareForRecycle {
|
|
132
143
|
[super prepareForRecycle];
|
|
133
144
|
|
|
145
|
+
// FIX: Force drop focus when leaving screen
|
|
146
|
+
[_customTextView resignFirstResponder];
|
|
147
|
+
|
|
134
148
|
[[UIMenuController sharedMenuController] hideMenuFromView:_customTextView];
|
|
135
149
|
[UIMenuController sharedMenuController].menuItems = nil;
|
|
136
150
|
|
|
137
151
|
_customTextView.text = nil;
|
|
138
152
|
_customTextView.selectedTextRange = nil;
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
|
|
154
|
+
// CRITICAL FIX: Do NOT clear _menuOptions here. Fabric's prop diffing will handle updates.
|
|
155
|
+
// If we clear it here, navigating away and back will result in an empty menu and crash iOS.
|
|
156
|
+
// _menuOptions = @[];
|
|
157
|
+
// _menuOptionsVector.clear();
|
|
141
158
|
|
|
142
159
|
[self unhideAllViews:self];
|
|
143
160
|
}
|
|
@@ -235,6 +252,11 @@ using namespace facebook::react;
|
|
|
235
252
|
// FORCING THE FOCUS: ensures the system doesn't dismiss our menu unexpectedly
|
|
236
253
|
[textView becomeFirstResponder];
|
|
237
254
|
|
|
255
|
+
// SAFETY NET: If options are empty (due to async loading), return standard copy to avoid crash
|
|
256
|
+
if (_menuOptions.count == 0) {
|
|
257
|
+
return [UIMenu menuWithTitle:@"" children:suggestedActions];
|
|
258
|
+
}
|
|
259
|
+
|
|
238
260
|
NSMutableArray<UIMenuElement *> *customActions = [[NSMutableArray alloc] init];
|
|
239
261
|
|
|
240
262
|
for (NSString *option in _menuOptions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thiagobueno/rn-selectable-text",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A library for custom text selection menus",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -164,4 +164,4 @@
|
|
|
164
164
|
"type": "fabric-view",
|
|
165
165
|
"version": "0.54.2"
|
|
166
166
|
}
|
|
167
|
-
}
|
|
167
|
+
}
|