React Native中AR QuickLook分享按钮禁用/功能修改方法咨询
Yes, you can customize or remove the share button in AR QuickLook by modifying the native iOS code wrapped by react-native-file-viewer. Here's how to do it:
Disable the Share Button Completely
- Open
node_modules/react-native-file-viewer/ios/RNFileViewerManager.m - Update the class interface to include the
QLPreviewControllerDelegateprotocol:@interface RNFileViewerManager () <QLPreviewControllerDelegate> - When initializing the
QLPreviewController, set its delegate toself:QLPreviewController *previewController = [[QLPreviewController alloc] init]; previewController.delegate = self; // Add this line previewController.dataSource = self; - Add the following delegate method to override the navigation item and remove the share button:
- (UINavigationItem *)previewController:(QLPreviewController *)controller navigationItemForPreviewItem:(id<QLPreviewItem>)previewItem { UINavigationItem *navItem = controller.navigationItem; navItem.rightBarButtonItems = nil; // Clear the default share button return navItem; }
Replace with Custom Share Functionality
If you want to keep a share button but change what it does (e.g., share a link instead of the full model file):
- Use the same delegate method to replace the default button with a custom one:
- (UINavigationItem *)previewController:(QLPreviewController *)controller navigationItemForPreviewItem:(id<QLPreviewItem>)previewItem { UINavigationItem *navItem = controller.navigationItem; // Create a custom action button UIBarButtonItem *customShareBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(triggerCustomShare:)]; navItem.rightBarButtonItems = @[customShareBtn]; return navItem; } - Add the custom share handler method:
- (void)triggerCustomShare:(UIBarButtonItem *)sender { // Example: Share a URL instead of the model file NSString *shareContent = @"https://your-app.com/model-viewer"; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[shareContent] applicationActivities:nil]; // Get the top view controller to present the share sheet UIViewController *topVC = [UIApplication sharedApplication].keyWindow.rootViewController; while (topVC.presentedViewController) { topVC = topVC.presentedViewController; } [topVC presentViewController:activityVC animated:YES completion:nil]; }
Keep Changes Persistent
Modifying node_modules directly will lose your changes when you run npm install or yarn install. Use patch-package to save your edits as a patch:
- Install the package:
npm install patch-package --save-dev - After making your changes, run:
npx patch-package react-native-file-viewer - A patch file will be created in the
patches/directory. It will automatically apply on future dependency installs.
Note: The canonical website approach you attempted is designed to let AR QuickLook share a link to your model instead of the raw file, but it doesn't disable the share button itself. That's why it didn't solve your problem.
内容的提问来源于stack exchange,提问作者Arima132
相关产品推荐
相关产品推荐

