diff --git a/apple/MarkdownTextInputDecoratorView.mm b/apple/MarkdownTextInputDecoratorView.mm index bffb8ade..bc9cbf4b 100644 --- a/apple/MarkdownTextInputDecoratorView.mm +++ b/apple/MarkdownTextInputDecoratorView.mm @@ -81,12 +81,9 @@ - (void)didMoveToWindow { } else if ([backedTextInputView isKindOfClass:[RCTUITextView class]]) { _textView = (RCTUITextView *)backedTextInputView; - _markdownTextStorageDelegate = [[MarkdownTextStorageDelegate alloc] init]; - _markdownTextStorageDelegate.markdownUtils = _markdownUtils; - _markdownTextStorageDelegate.textView = _textView; - // register delegate for future edits react_native_assert(_textView.textStorage.delegate == nil); + _markdownTextStorageDelegate = [[MarkdownTextStorageDelegate alloc] initWithTextView:_textView markdownUtils:_markdownUtils]; _textView.textStorage.delegate = _markdownTextStorageDelegate; #ifdef RCT_NEW_ARCH_ENABLED diff --git a/apple/MarkdownTextStorageDelegate.h b/apple/MarkdownTextStorageDelegate.h index bfdebbbd..e7cb244a 100644 --- a/apple/MarkdownTextStorageDelegate.h +++ b/apple/MarkdownTextStorageDelegate.h @@ -6,9 +6,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MarkdownTextStorageDelegate : NSObject -@property(nonatomic, nullable) RCTMarkdownUtils *markdownUtils; - -@property(nonatomic, nullable, strong) RCTUITextView *textView; +- (instancetype)initWithTextView:(nonnull RCTUITextView *)textView markdownUtils:(nonnull RCTMarkdownUtils *)markdownUtils; @end diff --git a/apple/MarkdownTextStorageDelegate.mm b/apple/MarkdownTextStorageDelegate.mm index ffd13a58..86051953 100644 --- a/apple/MarkdownTextStorageDelegate.mm +++ b/apple/MarkdownTextStorageDelegate.mm @@ -1,11 +1,24 @@ #import #import "react_native_assert.h" -@implementation MarkdownTextStorageDelegate +@implementation MarkdownTextStorageDelegate { + RCTMarkdownUtils *markdownUtils; + RCTUITextView *textView; +} + +- (instancetype)initWithTextView:(nonnull RCTUITextView *)textView markdownUtils:(nonnull RCTMarkdownUtils *)markdownUtils +{ + if ((self = [super init])) { + react_native_assert(_textView != nil); + react_native_assert(_markdownUtils != nil); + + _textView = textView; + _markdownUtils = markdownUtils; + } + return self; +} - (void)textStorage:(NSTextStorage *)textStorage didProcessEditing:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta { - react_native_assert(_markdownUtils != nil); - react_native_assert(_textView != nil); react_native_assert(_textView.defaultTextAttributes != nil); [_markdownUtils applyFormatting:textStorage withDefaultTextAttributes:_textView.defaultTextAttributes];