Skip to content

Commit 06c8e8f

Browse files
authored
fix(iOS): fix component layout issue (#915)
1 parent e6f63c2 commit 06c8e8f

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

example/src/HeadphonesCarouselExample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ export default function HeadphonesCarouselExample() {
261261
}
262262
)}
263263
>
264-
{data.map((item, index) => (
264+
{data.map(({ key, ...item }, index) => (
265265
<View collapsable={false} key={index}>
266266
<Item
267+
key={key}
267268
{...item}
268269
scrollOffsetAnimatedValue={scrollOffsetAnimatedValue}
269270
positionAnimatedValue={positionAnimatedValue}

ios/LEGACY/Fabric/LEGACY_RNCPagerViewComponentView.mm

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
9292
#pragma mark - React API
9393

9494
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
95-
UIViewController *wrapper = [[UIViewController alloc] initWithView:childComponentView];
96-
[_nativeChildrenViewControllers insertObject:wrapper atIndex:index];
97-
[self goTo:_currentIndex animated:NO];
95+
UIViewController *vc = [UIViewController new];
96+
[vc.view addSubview:childComponentView];
97+
[_nativeChildrenViewControllers insertObject:vc atIndex:index];
9898
}
9999

100100
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
101-
[[_nativeChildrenViewControllers objectAtIndex:index].view removeFromSuperview];
102-
[_nativeChildrenViewControllers objectAtIndex:index].view = nil;
101+
[childComponentView removeFromSuperview];
103102
[_nativeChildrenViewControllers removeObjectAtIndex:index];
104103

105104
NSInteger maxPage = _nativeChildrenViewControllers.count - 1;
@@ -119,11 +118,7 @@ -(void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics
119118

120119
-(void)prepareForRecycle {
121120
[super prepareForRecycle];
122-
123-
_nativeChildrenViewControllers = [[NSMutableArray alloc] init];
124-
[_nativePageViewController.view removeFromSuperview];
125121
_nativePageViewController = nil;
126-
127122
_currentIndex = -1;
128123
}
129124

0 commit comments

Comments
 (0)