Skip to content

Commit

Permalink
fix(flagship): add init script to patch rn images for ios 14
Browse files Browse the repository at this point in the history
This adds a script to iOS init that patches RCTUIImageViewAnimated.m to display images in iOS 14.

See issue here: facebook/react-native#29268
  • Loading branch information
bweissbart committed Sep 14, 2020
1 parent 94dfaa7 commit d517ec2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/flagship/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions packages/flagship/src/lib/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
`
);
}

0 comments on commit d517ec2

Please sign in to comment.