react-native-highlight-text-view 0.1.0 → 0.1.2

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.
@@ -73,6 +73,7 @@ using namespace facebook::react;
73
73
  CGFloat _paddingTop;
74
74
  CGFloat _paddingBottom;
75
75
  CGFloat _cornerRadius;
76
+ BOOL _isUpdatingText;
76
77
  }
77
78
 
78
79
  + (ComponentDescriptorProvider)componentDescriptorProvider
@@ -220,6 +221,20 @@ using namespace facebook::react;
220
221
  _layoutManager.paddingBottom = _paddingBottom;
221
222
  }
222
223
  }
224
+
225
+ if (oldViewProps.text != newViewProps.text) {
226
+ NSString *text = [[NSString alloc] initWithUTF8String: newViewProps.text.c_str()];
227
+ if (![_textView.text isEqualToString:text]) {
228
+ _isUpdatingText = YES;
229
+ _textView.text = text;
230
+ [self applyCharacterBackgrounds];
231
+ _isUpdatingText = NO;
232
+ }
233
+ }
234
+
235
+ if (oldViewProps.isEditable != newViewProps.isEditable) {
236
+ _textView.editable = newViewProps.isEditable;
237
+ }
223
238
 
224
239
  [super updateProps:props oldProps:oldProps];
225
240
  }
@@ -232,6 +247,14 @@ Class<RCTComponentViewProtocol> HighlightTextViewCls(void)
232
247
  - (void)textViewDidChange:(UITextView *)textView
233
248
  {
234
249
  [self applyCharacterBackgrounds];
250
+ if (!_isUpdatingText) {
251
+ if (_eventEmitter != nullptr) {
252
+ std::dynamic_pointer_cast<const HighlightTextViewEventEmitter>(_eventEmitter)
253
+ ->onChange(HighlightTextViewEventEmitter::OnChange{
254
+ .text = std::string([textView.text UTF8String] ?: "")
255
+ });
256
+ }
257
+ }
235
258
  }
236
259
 
237
260
  - (void)applyCharacterBackgrounds
@@ -1,4 +1,10 @@
1
- import { codegenNativeComponent, type ViewProps } from 'react-native';
1
+ import { codegenNativeComponent } from 'react-native';
2
+ import type { ViewProps } from 'react-native';
3
+ import type { BubblingEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
4
+
5
+ export interface OnChangeEventData {
6
+ readonly text: string;
7
+ }
2
8
 
3
9
  export interface HighlightTextViewProps extends ViewProps {
4
10
  color?: string;
@@ -11,6 +17,9 @@ export interface HighlightTextViewProps extends ViewProps {
11
17
  paddingRight?: string;
12
18
  paddingTop?: string;
13
19
  paddingBottom?: string;
20
+ text?: string;
21
+ isEditable?: boolean;
22
+ onChange?: BubblingEventHandler<OnChangeEventData>;
14
23
  }
15
24
 
16
25
  export default codegenNativeComponent<HighlightTextViewProps>(
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=codegen-types.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["codegen-types.d.ts"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,8 @@
1
- import { type ViewProps } from 'react-native';
1
+ import type { ViewProps } from 'react-native';
2
+ import type { BubblingEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface OnChangeEventData {
4
+ readonly text: string;
5
+ }
2
6
  export interface HighlightTextViewProps extends ViewProps {
3
7
  color?: string;
4
8
  textColor?: string;
@@ -10,6 +14,9 @@ export interface HighlightTextViewProps extends ViewProps {
10
14
  paddingRight?: string;
11
15
  paddingTop?: string;
12
16
  paddingBottom?: string;
17
+ text?: string;
18
+ isEditable?: boolean;
19
+ onChange?: BubblingEventHandler<OnChangeEventData>;
13
20
  }
14
21
  declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<HighlightTextViewProps>;
15
22
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"HighlightTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/HighlightTextViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtE,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;;AAED,wBAEE"}
1
+ {"version":3,"file":"HighlightTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/HighlightTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEtF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;CACpD;;AAED,wBAEE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-highlight-text-view",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A native text input for React Native that supports inline text highlighting",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -1,4 +1,10 @@
1
- import { codegenNativeComponent, type ViewProps } from 'react-native';
1
+ import { codegenNativeComponent } from 'react-native';
2
+ import type { ViewProps } from 'react-native';
3
+ import type { BubblingEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
4
+
5
+ export interface OnChangeEventData {
6
+ readonly text: string;
7
+ }
2
8
 
3
9
  export interface HighlightTextViewProps extends ViewProps {
4
10
  color?: string;
@@ -11,6 +17,9 @@ export interface HighlightTextViewProps extends ViewProps {
11
17
  paddingRight?: string;
12
18
  paddingTop?: string;
13
19
  paddingBottom?: string;
20
+ text?: string;
21
+ isEditable?: boolean;
22
+ onChange?: BubblingEventHandler<OnChangeEventData>;
14
23
  }
15
24
 
16
25
  export default codegenNativeComponent<HighlightTextViewProps>(
@@ -0,0 +1,14 @@
1
+ declare module 'react-native/Libraries/Types/CodegenTypes' {
2
+ export type DirectEventHandler<T = {}> = (event: { nativeEvent: T }) => void;
3
+ export type BubblingEventHandler<T = {}> = (event: {
4
+ nativeEvent: T;
5
+ }) => void;
6
+ }
7
+
8
+ declare module 'react-native/Libraries/Utilities/codegenNativeComponent' {
9
+ import type { HostComponent } from 'react-native';
10
+ export default function codegenNativeComponent<T>(
11
+ componentName: string,
12
+ options?: {}
13
+ ): HostComponent<T>;
14
+ }