diff --git a/ios/RCTBaseTextInputShadowView+Markdown.h b/ios/RCTBaseTextInputShadowView+Markdown.h deleted file mode 100644 index 5ad5814b..00000000 --- a/ios/RCTBaseTextInputShadowView+Markdown.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface RCTBaseTextInputShadowView (Markdown) - -- (NSAttributedString *)markdown_measurableAttributedText; - -@end - -NS_ASSUME_NONNULL_END diff --git a/ios/RCTBaseTextInputShadowView+Markdown.m b/ios/RCTBaseTextInputShadowView+Markdown.m deleted file mode 100644 index d9726873..00000000 --- a/ios/RCTBaseTextInputShadowView+Markdown.m +++ /dev/null @@ -1,49 +0,0 @@ -#import -#import -#import -#import -#import - -@implementation RCTBaseTextInputShadowView (Markdown) - -- (NSAttributedString *)markdown_measurableAttributedText -{ - // TODO: find a better way to check if Markdown is enabled - RCTBridge *bridge = [self valueForKey:@"_bridge"]; - RCTUIManager *uiManager = [bridge moduleForClass:[RCTUIManager class]]; - __block NSNumber *markdownEnabledNumber = @NO; - NSNumber *reactTag = self.reactTag; - RCTUnsafeExecuteOnMainQueueSync(^{ - UIView *view = [uiManager viewForReactTag:reactTag]; - if ([view isKindOfClass:[RCTBaseTextInputView class]]) { - RCTBaseTextInputView *textInput = (RCTBaseTextInputView *)view; - if ([textInput isMarkdownEnabled]) { - markdownEnabledNumber = @YES; - } - } - }); - - // Call the original method - NSAttributedString *output = [self markdown_measurableAttributedText]; - - if ([markdownEnabledNumber boolValue]) { - output = [RCTMarkdownUtils parseMarkdown:output.string]; - } - - return output; -} - -+ (void)load -{ - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - Class cls = [self class]; - SEL originalSelector = @selector(measurableAttributedText); - SEL swizzledSelector = @selector(markdown_measurableAttributedText); - Method originalMethod = class_getInstanceMethod(cls, originalSelector); - Method swizzledMethod = class_getInstanceMethod(cls, swizzledSelector); - method_exchangeImplementations(originalMethod, swizzledMethod); - }); -} - -@end diff --git a/ios/RCTBaseTextInputView+Markdown.h b/ios/RCTBaseTextInputView+Markdown.h index 277ffdcf..aeb65f56 100644 --- a/ios/RCTBaseTextInputView+Markdown.h +++ b/ios/RCTBaseTextInputView+Markdown.h @@ -8,6 +8,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)markdown_setAttributedText:(NSAttributedString *)attributedText; +- (void)markdown_updateLocalData; + @end NS_ASSUME_NONNULL_END diff --git a/ios/RCTBaseTextInputView+Markdown.m b/ios/RCTBaseTextInputView+Markdown.m index 70badc9a..135f2011 100644 --- a/ios/RCTBaseTextInputView+Markdown.m +++ b/ios/RCTBaseTextInputView+Markdown.m @@ -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); + } }); }