react-native-macos 0.71.28 → 0.71.29

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.
@@ -23,7 +23,7 @@ type NativeType = HostComponent<mixed>;
23
23
  type NativeCommands = TextInputNativeCommands<NativeType>;
24
24
 
25
25
  export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
26
- supportedCommands: ['focus', 'blur', 'setTextAndSelection'],
26
+ supportedCommands: ['focus', 'blur', 'setTextAndSelection', 'setGhostText'], // [macOS]
27
27
  });
28
28
 
29
29
  export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
@@ -23,7 +23,7 @@ type NativeType = HostComponent<mixed>;
23
23
  type NativeCommands = TextInputNativeCommands<NativeType>;
24
24
 
25
25
  export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
26
- supportedCommands: ['focus', 'blur', 'setTextAndSelection'],
26
+ supportedCommands: ['focus', 'blur', 'setTextAndSelection', 'setGhostText'], // [macOS]
27
27
  });
28
28
 
29
29
  export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
@@ -1038,6 +1038,7 @@ type ImperativeMethods = $ReadOnly<{|
1038
1038
  isFocused: () => boolean,
1039
1039
  getNativeRef: () => ?React.ElementRef<HostComponent<mixed>>,
1040
1040
  setSelection: (start: number, end: number) => void,
1041
+ setGhostText: (ghostText: ?string) => void, // [macOS]
1041
1042
  |}>;
1042
1043
 
1043
1044
  /**
@@ -1086,6 +1086,7 @@ type ImperativeMethods = $ReadOnly<{|
1086
1086
  isFocused: () => boolean,
1087
1087
  getNativeRef: () => ?React.ElementRef<HostComponent<mixed>>,
1088
1088
  setSelection: (start: number, end: number) => void,
1089
+ setGhostText: (ghostText: ?string) => void, // [macOS]
1089
1090
  |}>;
1090
1091
 
1091
1092
  const emptyFunctionThatReturnsTrue = () => true;
@@ -1366,6 +1367,14 @@ function InternalTextInput(props: Props): React.Node {
1366
1367
  }
1367
1368
  }
1368
1369
 
1370
+ // [macOS
1371
+ function setGhostText(ghostText: ?string) {
1372
+ if (inputRef.current != null) {
1373
+ viewCommands.setGhostText(inputRef.current, ghostText);
1374
+ }
1375
+ }
1376
+ // macOS]
1377
+
1369
1378
  // TODO: Fix this returning true on null === null, when no input is focused
1370
1379
  function isFocused(): boolean {
1371
1380
  return TextInputState.currentlyFocusedInput() === inputRef.current;
@@ -1407,6 +1416,7 @@ function InternalTextInput(props: Props): React.Node {
1407
1416
  ref.isFocused = isFocused;
1408
1417
  ref.getNativeRef = getNativeRef;
1409
1418
  ref.setSelection = setSelection;
1419
+ ref.setGhostText = setGhostText; // [macOS]
1410
1420
  }
1411
1421
  },
1412
1422
  });
@@ -22,8 +22,20 @@ export interface TextInputNativeCommands<T> {
22
22
  start: Int32,
23
23
  end: Int32,
24
24
  ) => void;
25
+ // [macOS
26
+ // NYI on Android
27
+ +setGhostText: (
28
+ viewRef: React.ElementRef<T>,
29
+ value: ?string, // in theory this is nullable
30
+ ) => void;
31
+ // macOS]
25
32
  }
26
33
 
27
- const supportedCommands = ['focus', 'blur', 'setTextAndSelection'];
34
+ const supportedCommands = [
35
+ 'focus',
36
+ 'blur',
37
+ 'setTextAndSelection',
38
+ 'setGhostText',
39
+ ]; // [macOS]
28
40
 
29
41
  export default supportedCommands;
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 71,
15
- patch: 28,
15
+ patch: 29,
16
16
  prerelease: null,
17
17
  };
@@ -56,6 +56,8 @@ NS_ASSUME_NONNULL_BEGIN
56
56
  - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
57
57
  #endif // macOS]
58
58
 
59
+ @property (nonatomic, getter=isGhostTextChanging) BOOL ghostTextChanging; // [macOS]
60
+
59
61
  @end
60
62
 
61
63
  NS_ASSUME_NONNULL_END
@@ -382,7 +382,10 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
382
382
  {
383
383
  if (_lastStringStateWasUpdatedWith && ![_lastStringStateWasUpdatedWith isEqual:_backedTextInputView.attributedText]) {
384
384
  [self textViewDidChange:_backedTextInputView];
385
- _ignoreNextTextInputCall = YES;
385
+
386
+ if (![_backedTextInputView isGhostTextChanging]) { // [macOS]
387
+ _ignoreNextTextInputCall = YES;
388
+ } // [macOS]
386
389
  }
387
390
  _lastStringStateWasUpdatedWith = _backedTextInputView.attributedText;
388
391
  [self textViewProbablyDidChangeSelection];
@@ -84,6 +84,8 @@ NS_ASSUME_NONNULL_BEGIN
84
84
  // Use `attributedText.string` instead.
85
85
  @property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;
86
86
 
87
+ @property (nonatomic, getter=isGhostTextChanging) BOOL ghostTextChanging; // [macOS]
88
+
87
89
  @end
88
90
 
89
91
  NS_ASSUME_NONNULL_END
@@ -68,6 +68,8 @@ NS_ASSUME_NONNULL_BEGIN
68
68
  @property (nonatomic, assign) BOOL showSoftInputOnFocus;
69
69
  #endif // [macOS]
70
70
 
71
+ @property (nonatomic, copy, nullable) NSString *ghostText; // [macOS]
72
+
71
73
  /**
72
74
  Sets selection intext input if both start and end are within range of the text input.
73
75
  **/
@@ -26,6 +26,9 @@
26
26
  @implementation RCTBaseTextInputView {
27
27
  __weak RCTBridge *_bridge;
28
28
  __weak id<RCTEventDispatcherProtocol> _eventDispatcher;
29
+
30
+ NSInteger _ghostTextPosition; // [macOS] only valid if _ghostText != nil
31
+
29
32
  BOOL _hasInputAccesoryView;
30
33
  // [macOS] remove explicit _predictedText ivar declaration
31
34
  BOOL _didMoveToWindow;
@@ -164,7 +167,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
164
167
 
165
168
  textNeedsUpdate = ([self textOf:attributedTextCopy equals:backedTextInputViewTextCopy] == NO);
166
169
 
167
- if (eventLag == 0 && textNeedsUpdate) {
170
+ if ((eventLag == 0 || self.backedTextInputView.ghostTextChanging) && textNeedsUpdate) { // [macOS]
168
171
  #if !TARGET_OS_OSX // [macOS]
169
172
  UITextRange *selection = self.backedTextInputView.selectedTextRange;
170
173
  #else // [macOS
@@ -191,7 +194,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
191
194
  [self.backedTextInputView positionFromPosition:self.backedTextInputView.beginningOfDocument offset:newOffset];
192
195
  [self.backedTextInputView setSelectedTextRange:[self.backedTextInputView textRangeFromPosition:position
193
196
  toPosition:position]
194
- notifyDelegate:YES];
197
+ notifyDelegate:!self.backedTextInputView.ghostTextChanging]; // [macOS]
195
198
  }
196
199
  #else // [macOS
197
200
  if (selection.length == 0) {
@@ -200,7 +203,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
200
203
  NSInteger offsetFromEnd = oldTextLength - start;
201
204
  NSInteger newOffset = self.backedTextInputView.attributedText.length - offsetFromEnd;
202
205
  [self.backedTextInputView setSelectedTextRange:NSMakeRange(newOffset, 0)
203
- notifyDelegate:YES];
206
+ notifyDelegate:!self.backedTextInputView.ghostTextChanging];
204
207
  }
205
208
  #endif // macOS]
206
209
 
@@ -415,6 +418,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
415
418
 
416
419
  - (void)textInputDidEndEditing
417
420
  {
421
+ self.ghostText = nil; // [macOS]
422
+
418
423
  [_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
419
424
  reactTag:self.reactTag
420
425
  text:[self.backedTextInputView.attributedText.string copy]
@@ -524,6 +529,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
524
529
  {
525
530
  id<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
526
531
 
532
+ self.ghostText = nil; // [macOS]
533
+
527
534
  if (!backedTextInputView.textWasPasted) {
528
535
  [_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
529
536
  reactTag:self.reactTag
@@ -590,7 +597,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
590
597
  withString:text];
591
598
  }
592
599
 
593
- if (_onTextInput) {
600
+ if (_onTextInput && !self.backedTextInputView.ghostTextChanging) { // [macOS]
594
601
  _onTextInput(@{
595
602
  // We copy the string here because if it's a mutable string it may get released before we stop using it on a
596
603
  // different thread, causing a crash.
@@ -624,20 +631,24 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
624
631
  [self setPredictedText:backedTextInputView.attributedText.string]; // [macOS]
625
632
  }
626
633
 
627
- _nativeEventCount++;
634
+ if (!self.backedTextInputView.ghostTextChanging) { // [macOS]
635
+ _nativeEventCount++;
628
636
 
629
- if (_onChange) {
630
- _onChange(@{
631
- @"text" : [self.attributedText.string copy],
632
- @"target" : self.reactTag,
633
- @"eventCount" : @(_nativeEventCount),
634
- });
635
- }
637
+ if (_onChange) {
638
+ _onChange(@{
639
+ @"text" : [self.attributedText.string copy],
640
+ @"target" : self.reactTag,
641
+ @"eventCount" : @(_nativeEventCount),
642
+ });
643
+ }
644
+ } // [macOS]
636
645
  }
637
646
 
638
647
  - (void)textInputDidChangeSelection
639
648
  {
640
- if (!_onSelectionChange) {
649
+ self.ghostText = nil; // [macOS]
650
+
651
+ if (!_onSelectionChange || self.backedTextInputView.ghostTextChanging) { // [macOS]
641
652
  return;
642
653
  }
643
654
 
@@ -875,6 +886,92 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
875
886
  }
876
887
  #endif // [macOS]
877
888
 
889
+ // [macOS
890
+
891
+ - (NSDictionary<NSAttributedStringKey, id> *)ghostTextAttributes
892
+ {
893
+ RCTUIView<RCTBackedTextInputViewProtocol> *backedTextInputView = self.backedTextInputView;
894
+ NSMutableDictionary<NSAttributedStringKey, id> *textAttributes =
895
+ [backedTextInputView.defaultTextAttributes mutableCopy] ?: [NSMutableDictionary new];
896
+
897
+ if (@available(iOS 13.0, *)) {
898
+ [textAttributes setValue:backedTextInputView.placeholderColor ?: [RCTUIColor placeholderTextColor]
899
+ forKey:NSForegroundColorAttributeName];
900
+ } else {
901
+ if (backedTextInputView.placeholderColor) {
902
+ [textAttributes setValue:backedTextInputView.placeholderColor forKey:NSForegroundColorAttributeName];
903
+ } else {
904
+ [textAttributes removeObjectForKey:NSForegroundColorAttributeName];
905
+ }
906
+ }
907
+
908
+ return textAttributes;
909
+ }
910
+
911
+ - (void)setGhostText:(NSString *)ghostText {
912
+ RCTTextSelection *selection = self.selection;
913
+ NSString *newGhostText = ghostText.length > 0 ? ghostText : nil;
914
+
915
+ if (selection.start != selection.end) {
916
+ newGhostText = nil;
917
+ }
918
+
919
+ if ((_ghostText == nil && newGhostText == nil) || [_ghostText isEqual:newGhostText]) {
920
+ return;
921
+ }
922
+
923
+ if (self.backedTextInputView.ghostTextChanging) {
924
+ // look out for nested callbacks -- this can happen for example when selection changes in response to
925
+ // attributed text changing. Such callbacks are initiated by Apple, or we could suppress this other ways.
926
+ return;
927
+ }
928
+
929
+ self.backedTextInputView.ghostTextChanging = YES;
930
+
931
+ if (_ghostText != nil) {
932
+ BOOL shouldDeleteGhostText = YES;
933
+ NSRange ghostTextRange = NSMakeRange(_ghostTextPosition, _ghostText.length);
934
+ NSMutableAttributedString *attributedString = [self.attributedText mutableCopy];
935
+
936
+ if ([attributedString length] < NSMaxRange(ghostTextRange)) {
937
+ RCTAssert(false, @"Ghost text not fully present in text view text");
938
+ shouldDeleteGhostText = NO;
939
+ }
940
+
941
+ NSString *actualGhostText = shouldDeleteGhostText
942
+ ? [[attributedString attributedSubstringFromRange:ghostTextRange] string]
943
+ : nil;
944
+
945
+ if (![actualGhostText isEqual:_ghostText]) {
946
+ RCTAssert(false, @"Ghost text does not match text view text");
947
+ shouldDeleteGhostText = NO;
948
+ }
949
+
950
+ if (shouldDeleteGhostText) {
951
+ [attributedString deleteCharactersInRange:ghostTextRange];
952
+ self.attributedText = attributedString;
953
+ [self setSelectionStart:selection.start selectionEnd:selection.end];
954
+ }
955
+ }
956
+
957
+ _ghostText = [newGhostText copy];
958
+ _ghostTextPosition = selection.start;
959
+
960
+ if (_ghostText != nil) {
961
+ NSMutableAttributedString *attributedString = [self.attributedText mutableCopy];
962
+ NSAttributedString *ghostAttributedString = [[NSAttributedString alloc] initWithString:_ghostText
963
+ attributes:self.ghostTextAttributes];
964
+
965
+ [attributedString insertAttributedString:ghostAttributedString atIndex:_ghostTextPosition];
966
+ self.attributedText = attributedString;
967
+ [self setSelectionStart:_ghostTextPosition selectionEnd:_ghostTextPosition];
968
+ }
969
+
970
+ self.backedTextInputView.ghostTextChanging = NO;
971
+ }
972
+
973
+ // macOS]
974
+
878
975
  #pragma mark - Helpers
879
976
 
880
977
  static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange, NSRange *secondRange)
@@ -169,6 +169,17 @@ RCT_EXPORT_METHOD(setTextAndSelection
169
169
  }];
170
170
  }
171
171
 
172
+ // [macOS
173
+ RCT_EXPORT_METHOD(setGhostText
174
+ :(nonnull NSNumber *)reactTag
175
+ :(NSString *)text) {
176
+
177
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTPlatformView *> *viewRegistry) {
178
+ [(RCTBaseTextInputView *)viewRegistry[reactTag] setGhostText:text];
179
+ }];
180
+ }
181
+ // macOS]
182
+
172
183
  #pragma mark - RCTUIManagerObserver
173
184
 
174
185
  - (void)uiManagerWillPerformMounting:(__unused RCTUIManager *)uiManager
@@ -61,6 +61,8 @@ NS_ASSUME_NONNULL_BEGIN
61
61
  @property (weak, nullable) id<RCTUITextFieldDelegate> delegate;
62
62
  #endif // macOS]
63
63
 
64
+ @property (nonatomic, getter=isGhostTextChanging) BOOL ghostTextChanging; // [macOS]
65
+
64
66
  @end
65
67
 
66
68
  NS_ASSUME_NONNULL_END
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(71),
26
- RCTVersionPatch: @(28),
26
+ RCTVersionPatch: @(29),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.71.28
1
+ VERSION_NAME=0.71.29
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  # JVM Versions
@@ -17,6 +17,6 @@ public class ReactNativeVersion {
17
17
  public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
18
18
  "major", 0,
19
19
  "minor", 71,
20
- "patch", 28,
20
+ "patch", 29,
21
21
  "prerelease", null);
22
22
  }
@@ -146,6 +146,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
146
146
  private static final int BLUR_TEXT_INPUT = 2;
147
147
  private static final int SET_MOST_RECENT_EVENT_COUNT = 3;
148
148
  private static final int SET_TEXT_AND_SELECTION = 4;
149
+ private static final int SET_GHOST_TEXT = 5; // [macOS]
149
150
 
150
151
  private static final int INPUT_TYPE_KEYBOARD_NUMBER_PAD = InputType.TYPE_CLASS_NUMBER;
151
152
  private static final int INPUT_TYPE_KEYBOARD_DECIMAL_PAD =
@@ -272,7 +273,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
272
273
 
273
274
  @Override
274
275
  public @Nullable Map<String, Integer> getCommandsMap() {
275
- return MapBuilder.of("focusTextInput", FOCUS_TEXT_INPUT, "blurTextInput", BLUR_TEXT_INPUT);
276
+ return MapBuilder.of("focusTextInput", FOCUS_TEXT_INPUT, "blurTextInput", BLUR_TEXT_INPUT, "setGhostText", SET_GHOST_TEXT); // [macOS]
276
277
  }
277
278
 
278
279
  @Override
@@ -291,6 +292,11 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
291
292
  case SET_TEXT_AND_SELECTION:
292
293
  this.receiveCommand(reactEditText, "setTextAndSelection", args);
293
294
  break;
295
+ // [macOS
296
+ case SET_GHOST_TEXT:
297
+ this.receiveCommand(reactEditText, "setGhostText", args);
298
+ break;
299
+ // macOS]
294
300
  }
295
301
  }
296
302
 
@@ -325,6 +331,12 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
325
331
  }
326
332
  reactEditText.maybeSetSelection(mostRecentEventCount, start, end);
327
333
  break;
334
+ // [macOS
335
+ case "setGhostText":
336
+ default:
337
+ throw new IllegalArgumentException(
338
+ "Unsupported command setGhostText received by ReactTextInputManager.");
339
+ // macOS]
328
340
  }
329
341
  }
330
342
 
@@ -17,7 +17,7 @@ namespace facebook::react {
17
17
  constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 71;
20
- int32_t Patch = 28;
20
+ int32_t Patch = 29;
21
21
  std::string_view Prerelease = "";
22
22
  } ReactNativeVersion;
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.71.28",
3
+ "version": "0.71.29",
4
4
  "bin": "./cli.js",
5
5
  "description": "React Native for macOS",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "react": "18.2.0",
15
- "react-native-macos": "0.71.28"
15
+ "react-native-macos": "0.71.29"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@babel/core": "^7.20.0",