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

Fix style update with emojis on iOS #318

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 5 additions & 3 deletions ios/MarkdownTextInputDecoratorView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@
{
_markdownStyle = markdownStyle;
[_markdownUtils setMarkdownStyle:markdownStyle];

// apply new styles
#ifdef RCT_NEW_ARCH_ENABLED
[_textInput textInputDidChange]; // apply new styles
[_textInput _setAttributedString:_textInput.attributedText];

Check failure on line 106 in ios/MarkdownTextInputDecoratorView.mm

View workflow job for this annotation

GitHub Actions / build (Fabric)

property 'attributedText' not found on object of type 'RCTTextInputComponentView *'
#else
[_textInput setAttributedText:_textInput.attributedText]; // apply new styles
#endif
[_textInput setAttributedText:_textInput.attributedText];
#endif /* RCT_NEW_ARCH_ENABLED */
}

@end
2 changes: 2 additions & 0 deletions ios/RCTBaseTextInputView+Markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ NS_ASSUME_NONNULL_BEGIN

- (void)markdown_setAttributedText:(NSAttributedString *)attributedText;

- (BOOL)markdown_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText;

- (void)markdown_updateLocalData;

@end
Expand Down
19 changes: 19 additions & 0 deletions ios/RCTBaseTextInputView+Markdown.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
[self markdown_setAttributedText:attributedText];
}

- (BOOL)markdown_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText
{
RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
if (markdownUtils != nil) {
return [newText isEqualToAttributedString:oldText];
}

return [self markdown_textOf:newText equals:oldText];
}

- (void)markdown_updateLocalData
{
RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
Expand Down Expand Up @@ -63,12 +73,21 @@

{
// swizzle updateLocalData
SEL originalSelector = @selector(updateLocalData);

Check warning on line 76 in ios/RCTBaseTextInputView+Markdown.mm

View workflow job for this annotation

GitHub Actions / build (Paper)

undeclared selector 'updateLocalData' [-Wundeclared-selector]
SEL swizzledSelector = @selector(markdown_updateLocalData);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}

{
// swizzle textOf
SEL originalSelector = @selector(textOf:equals:);

Check warning on line 85 in ios/RCTBaseTextInputView+Markdown.mm

View workflow job for this annotation

GitHub Actions / build (Paper)

undeclared selector 'textOf:equals:' [-Wundeclared-selector]
SEL swizzledSelector = @selector(markdown_textOf:equals:);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}

Expand Down
4 changes: 3 additions & 1 deletion ios/RCTTextInputComponentView+Markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ NS_ASSUME_NONNULL_BEGIN

- (void)markdown__setAttributedString:(NSAttributedString *)attributedString;

- (void)textInputDidChange;
- (BOOL)markdown__textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText;

- (void)_setAttributedString:(NSAttributedString *)attributedString;

@end

Expand Down
35 changes: 29 additions & 6 deletions ios/RCTTextInputComponentView+Markdown.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,39 @@ - (void)markdown__setAttributedString:(NSAttributedString *)attributedString
[self markdown__setAttributedString:attributedString];
}

- (BOOL)markdown__textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText
{
RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils];
if (markdownUtils != nil) {
return [newText isEqualToAttributedString:oldText];
}

return [self markdown__textOf:newText equals:oldText];
}

+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class cls = [self class];
SEL originalSelector = @selector(_setAttributedString:);
SEL swizzledSelector = @selector(markdown__setAttributedString:);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
{
// swizzle _setAttributedString
Class cls = [self class];
SEL originalSelector = @selector(_setAttributedString:);
SEL swizzledSelector = @selector(markdown__setAttributedString:);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}

{
// swizzle _textOf
Class cls = [self class];
SEL originalSelector = @selector(_textOf:equals:);
SEL swizzledSelector = @selector(markdown__textOf:equals:);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}

Expand Down
Loading