From df66b7a4d2796c437f86d3d60741280b1f9b2d23 Mon Sep 17 00:00:00 2001 From: Jiayan Zhuang Date: Tue, 4 Aug 2020 15:09:44 -0700 Subject: [PATCH] Add UIContentSizeCategoryDidChangeNotification to re-render text Summary: Changelog: [Internal] - Add UIContentSizeCategoryDidChangeNotification to re-render text We don't need to restart the app to re-render text now, but we still need to swipe the screen or click on buttons to force to refresh. We may address this in the future. Reviewed By: PeteTheHeat Differential Revision: D22867293 fbshipit-source-id: 4747a45adc2bdc638cf7ef9c07a9484e48600583 --- React/Fabric/RCTSurfacePresenter.mm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 82c1d6a449..4d65ca882b 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -120,6 +120,11 @@ static BackgroundExecutor RCTGetBackgroundExecutor() _observers = [NSMutableArray array]; _scheduler = [self _createScheduler]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_handleContentSizeCategoryDidChangeNotification:) + name:UIContentSizeCategoryDidChangeNotification + object:nil]; } return self; @@ -425,6 +430,23 @@ static BackgroundExecutor RCTGetBackgroundExecutor() }]; } +- (void)_handleContentSizeCategoryDidChangeNotification:(NSNotification *)notification +{ + RCTScheduler *scheduler = [self _scheduler]; + + [_surfaceRegistry enumerateWithBlock:^(NSEnumerator *enumerator) { + for (RCTFabricSurface *surface in enumerator) { + LayoutContext layoutContext = RCTGetLayoutContext(); + + LayoutConstraints layoutConstraints = RCTGetLayoutConstraintsForSize(surface.minimumSize, surface.maximumSize); + + [scheduler constraintSurfaceLayoutWithLayoutConstraints:layoutConstraints + layoutContext:layoutContext + surfaceId:surface.rootTag]; + } + }]; +} + #pragma mark - RCTSchedulerDelegate - (void)schedulerDidFinishTransaction:(MountingCoordinator::Shared const &)mountingCoordinator