deps: patch view-shot for RN 0.84
This commit is contained in:
@@ -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.');
|
||||
})();
|
||||
|
||||
@@ -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 <rnviewshot/rnviewshot.h>
|
||||
#endif`;
|
||||
|
||||
const importReplacement = `#ifdef RCT_NEW_ARCH_ENABLED
|
||||
#import <rnviewshot/rnviewshot.h>
|
||||
#endif
|
||||
|
||||
#if __has_include(<React/RCTScrollViewComponentView.h>)
|
||||
|
||||
// Fabric available
|
||||
#import <React/RCTScrollViewComponentView.h>
|
||||
typedef RCTScrollViewComponentView RNSnapshotScrollViewHost;
|
||||
|
||||
#else
|
||||
|
||||
// Fallback to legacy
|
||||
#import <React/RCTScrollView.h>
|
||||
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 <React/RCTScrollView.h>\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');
|
||||
}
|
||||
Reference in New Issue
Block a user