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

Parse string while setting local copy of attributed string #3

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 0 additions & 11 deletions ios/RCTBaseTextInputShadowView+Markdown.h

This file was deleted.

49 changes: 0 additions & 49 deletions ios/RCTBaseTextInputShadowView+Markdown.m

This file was deleted.

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

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

- (void)markdown_updateLocalData;

@end

NS_ASSUME_NONNULL_END
34 changes: 29 additions & 5 deletions ios/RCTBaseTextInputView+Markdown.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,40 @@ - (void)markdown_setAttributedText:(NSAttributedString *)attributedText
[self markdown_setAttributedText:attributedText];
}

- (void)markdown_updateLocalData
{
if ([self isMarkdownEnabled]) {
NSAttributedString *attributedText = [RCTMarkdownUtils parseMarkdown:self.backedTextInputView.attributedText.string];
[self.backedTextInputView setAttributedText:attributedText];
}

// Call the original method
[self markdown_updateLocalData];
}

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

{
// swizzle setAttributedText
SEL originalSelector = @selector(setAttributedText:);
SEL swizzledSelector = @selector(markdown_setAttributedText:);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}

{
// swizzle setAttributedText
SEL originalSelector = @selector(updateLocalData);
SEL swizzledSelector = @selector(markdown_updateLocalData);
Method originalMethod = class_getInstanceMethod(cls, originalSelector);
Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}

Expand Down