diff --git a/patches/index.mjs b/patches/index.mjs index 7205c6454..c143f907d 100644 --- a/patches/index.mjs +++ b/patches/index.mjs @@ -6,6 +6,7 @@ import { patchJcenter } from './patch-jcenter.mjs'; import { patchNativeEventEmitter } from './patch-native-event-emitter.mjs'; import { patchReactNativeNotifications } from './patch-react-native-notifications.mjs'; import { patchNobleHashes } from './patch-noble-hashes.mjs'; +import { patchViewShot } from './patch-view-shot.mjs'; console.log('Running postinstall patches...\n'); @@ -15,6 +16,7 @@ console.log('Running postinstall patches...\n'); patchNativeEventEmitter(); patchReactNativeNotifications(); patchNobleHashes(); + patchViewShot(); console.log('\nAll patches applied successfully.'); })(); diff --git a/patches/patch-view-shot.mjs b/patches/patch-view-shot.mjs new file mode 100644 index 000000000..993441149 --- /dev/null +++ b/patches/patch-view-shot.mjs @@ -0,0 +1,73 @@ +// Patch react-native-view-shot for RN 0.84 Fabric compatibility. +// RCTScrollView was removed in RN 0.84; use RCTScrollViewComponentView on +// Fabric builds instead. +// Based on https://github.com/gre/react-native-view-shot/pull/584 +// Can be removed once react-native-view-shot ships a release with this fix. + +import fs from 'fs'; + +export function patchViewShot() { + console.log('Patching react-native-view-shot (RN 0.84 Fabric compat)'); + + const filePath = + './node_modules/react-native-view-shot/ios/RNViewShot.mm'; + + if (!fs.existsSync(filePath)) { + console.log(' - Skipping: RNViewShot.mm not found'); + return; + } + + let content = fs.readFileSync(filePath, 'utf8'); + + // 1. Add the Fabric/legacy scroll view typedef after the existing #ifdef block + const importAnchor = `#ifdef RCT_NEW_ARCH_ENABLED +#import +#endif`; + + const importReplacement = `#ifdef RCT_NEW_ARCH_ENABLED +#import +#endif + +#if __has_include() + + // Fabric available + #import + typedef RCTScrollViewComponentView RNSnapshotScrollViewHost; + +#else + + // Fallback to legacy + #import + typedef RCTScrollView RNSnapshotScrollViewHost; + +#endif`; + + if (!content.includes('RNSnapshotScrollViewHost')) { + content = content.replace(importAnchor, importReplacement); + } + + // 2. Remove the now-unnecessary standalone RCTScrollView import + content = content.replace('#import \n', ''); + + // 3. Replace RCTScrollView usage in snapshotContentContainer logic + content = content.replace( + `if (![view isKindOfClass:[RCTScrollView class]]) { + reject(RCTErrorUnspecified, [NSString stringWithFormat:@"snapshotContentContainer can only be used on a RCTScrollView. instead got: %@", view], nil); + return; + } + RCTScrollView* rctScrollView = view; + scrollView = rctScrollView.scrollView;`, + `if (![view isKindOfClass:[RNSnapshotScrollViewHost class]]) { + reject(RCTErrorUnspecified, + [NSString stringWithFormat:@"snapshotContentContainer can only be used on a ScrollView host. instead got: %@", view], + nil); + return; + } + + RNSnapshotScrollViewHost *host = (RNSnapshotScrollViewHost *)view; + UIScrollView *scrollView = host.scrollView;` + ); + + fs.writeFileSync(filePath, content); + console.log(' - Patched RNViewShot.mm'); +}