From d517ec2baac2c7604b9e98e3392016ec54121607 Mon Sep 17 00:00:00 2001 From: Brett Weissbart Date: Wed, 5 Aug 2020 17:23:44 -0400 Subject: [PATCH] fix(flagship): add init script to patch rn images for ios 14 This adds a script to iOS init that patches RCTUIImageViewAnimated.m to display images in iOS 14. See issue here: https://github.com/facebook/react-native/issues/29268 --- packages/flagship/src/commands/init.ts | 2 ++ packages/flagship/src/lib/ios.ts | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/flagship/src/commands/init.ts b/packages/flagship/src/commands/init.ts index abffc2c43a..a1d32d0070 100644 --- a/packages/flagship/src/commands/init.ts +++ b/packages/flagship/src/commands/init.ts @@ -215,6 +215,8 @@ function initIOS( ios.backgroundModes(configuration); // Add background modes ios.sentryProperties(configuration); ios.setEnvSwitcherInitialEnv(configuration, environmentIdentifier); + ios.patchRCTUIImageViewAnimated(); + if (configuration.ios) { if (configuration.ios.pods) { if (configuration.ios.pods.sources) { diff --git a/packages/flagship/src/lib/ios.ts b/packages/flagship/src/lib/ios.ts index 3fbc1ad9a2..102b6699da 100644 --- a/packages/flagship/src/lib/ios.ts +++ b/packages/flagship/src/lib/ios.ts @@ -417,3 +417,31 @@ export function setEnvSwitcherInitialEnv(configuration: Config, env: string): vo `@"${env}"; // [EnvSwitcher initialEnvName]` ); } + +/** + * Patches RCTUIImageViewAnimated.m to fix displayLayer() to support iOS 14. + * + * @see https://github.com/facebook/react-native/issues/29268 + */ +export function patchRCTUIImageViewAnimated(): void { + helpers.logInfo(`patching RCTUIImageViewAnimated.m to support iOS 14`); + + const rnImagePath = path.project.resolve( + 'node_modules', 'react-native', 'Libraries', 'Image', 'RCTUIImageViewAnimated.m' + ); + + fs.update( + rnImagePath, + /\(void\)displayLayer[\s\S]+?(?=#pragma)/g, + `(void)displayLayer:(CALayer *)layer +{ + if (_currentFrame) { + layer.contentsScale = self.animatedImageScale; + layer.contents = (__bridge id)_currentFrame.CGImage; + } + [super displayLayer:layer]; +} + +` + ); +}