Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

T3MarkdownTextRun.mm

72 lines2.1 KB

1#import "T3MarkdownTextRun.h"
2#import "T3MarkdownText.h"
3#import "T3MarkdownTextRunComponentDescriptor.h"
4#import <react/renderer/components/T3MarkdownTextSpec/EventEmitters.h>
5#import <react/renderer/components/T3MarkdownTextSpec/Props.h>
6#import <react/renderer/components/T3MarkdownTextSpec/RCTComponentViewHelpers.h>
7#import "RCTFabricComponentsPlugins.h"
8#import "Utils.h"
9​
10using namespace facebook::react;
11​
12@interface T3MarkdownTextRun () <RCTT3MarkdownTextRunViewProtocol>
13​
14@end
15​
16@implementation T3MarkdownTextRun {
17 NSString * _text;
18 RCTBubblingEventBlock _onPress;
19 RCTBubblingEventBlock _onLongPress;
21​
22+ (ComponentDescriptorProvider)componentDescriptorProvider
24 return concreteComponentDescriptorProvider<T3MarkdownTextRunComponentDescriptor>();
26​
27- (instancetype)initWithFrame:(CGRect)frame
29 if (self = [super initWithFrame:frame]) {
30 static const auto defaultProps = std::make_shared<const T3MarkdownTextRunProps>();
31 _props = defaultProps;
32 }
33 return self;
35​
36- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
38 const auto &oldViewProps = *std::static_pointer_cast<T3MarkdownTextRunProps const>(_props);
39 const auto &newViewProps = *std::static_pointer_cast<T3MarkdownTextRunProps const>(props);
40​
41 if (newViewProps.text != oldViewProps.text) {
42 NSString *text = [NSString stringWithUTF8String:newViewProps.text.c_str()];
43 _text = text;
44 }
45​
46 [super updateProps:props oldProps:oldProps];
48​
49- (void)onPress {
50 if (_eventEmitter != nullptr) {
51 std::dynamic_pointer_cast<const facebook::react::T3MarkdownTextRunEventEmitter>(_eventEmitter)
52 ->onPress(facebook::react::T3MarkdownTextRunEventEmitter::OnPress{});
53 }
55​
56- (void)onLongPress {
57 if (_eventEmitter != nullptr) {
58 std::dynamic_pointer_cast<const facebook::react::T3MarkdownTextRunEventEmitter>(_eventEmitter)
59 ->onLongPress(facebook::react::T3MarkdownTextRunEventEmitter::OnLongPress{});
60 }
62​
63+ (BOOL)shouldBeRecycled {
64 return NO;
66​
67Class<RCTComponentViewProtocol> T3MarkdownTextRunCls(void)
69 return T3MarkdownTextRun.class;
71​
72@end