Skip to content

Commit 9eb9682

Browse files
committed
fix: iOS props not applied if same view is unmounted and remounted
1 parent 8d62c2a commit 9eb9682

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ios/RNSketchCanvasViewComponent.mm

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ @interface RNTSketchCanvas () <RCTRNTSketchCanvasViewProtocol>
2020

2121
@implementation RNTSketchCanvas {
2222
RNSketchCanvas * _view;
23+
BOOL _isInitialValueSet;
2324
}
2425

2526
+ (void)load
@@ -38,8 +39,6 @@ - (void)setupView {
3839
_view = [[RNSketchCanvas alloc] init];
3940
self.contentView = _view;
4041
_view.eventDelegate = self;
41-
self.backgroundColor = [UIColor clearColor];
42-
self.clearsContextBeforeDrawing = YES;
4342
}
4443

4544
- (instancetype)initWithFrame:(CGRect)frame
@@ -60,12 +59,15 @@ -(void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
6059

6160
-(void)prepareForRecycle {
6261
[super prepareForRecycle];
63-
62+
6463
if (_view) {
6564
[(RNSketchCanvas *)_view invalidate];
6665
[_view removeFromSuperview];
66+
6767
[self setupView];
6868
}
69+
70+
_isInitialValueSet = NO;
6971
}
7072

7173
- (NSDictionary*)RNTSketchCanvasTextStructToDict:(const RNTSketchCanvasTextStruct&)txt {
@@ -94,7 +96,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
9496
const auto &oldViewProps = *std::static_pointer_cast<RNTSketchCanvasProps const>(_props);
9597
const auto &newViewProps = *std::static_pointer_cast<RNTSketchCanvasProps const>(props);
9698

97-
if (oldViewProps.text.size() != newViewProps.text.size()) {
99+
if (!_isInitialValueSet || oldViewProps.text.size() != newViewProps.text.size()) {
98100
NSMutableArray *textArray = [NSMutableArray array];
99101
for (const auto& txt : newViewProps.text) {
100102
NSDictionary *textDict = [self RNTSketchCanvasTextStructToDict:txt];
@@ -144,6 +146,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
144146
contentMode:mode];
145147
}
146148
}
149+
150+
_isInitialValueSet = YES;
147151

148152
[super updateProps:props oldProps:oldProps];
149153
}

0 commit comments

Comments
 (0)