-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Can RCTViewComponentView get access RCTBridge's bundleURL or launchOptions property? #51010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Tip Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.77.2. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
Tip Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
Hi @nanatlantica, thanks for the issue. The New Architecture is more opinionated on how to handle lifecycle and on how to let components and modules communicate. Can you explain what is your use case, and what you are trying to achieve, so that we can suggest an alternative? |
Hi @cipolleschi ,Thanks for reply. For example, here is my code:
{ [[self getCurrentNavigationController] pushViewController:vc animatiomType:AHNavigationViewAnimationTypeBottomToTop]; I create a RCTBridge instance with specificed launchOptions : an UIViewController instance,then I use this UIViewController instance to call push or pop function in legacy component. |
If that's your use case, I don't think you should use any actual React Native specific detail. Also, is your Fabric component a navigation primitive? Are you creating a navigation library? |
@cipolleschi Yes, this is one type of scenario. I also have several other scenarios here. For example: this control needs to report some data to the server. These data are placed in the launchOptions when initializing the RCTBridge. How can I obtain this data that needs to be reported? |
@cipolleschi ,any suggestions for my question? |
I believe your app is putting those data in the // SingletonDataStore.h
#import <Foundation/Foundation.h>
@interface SingletonDataStore : NSObject
+ (instancetype)sharedInstance;
- (void)setData:(id)data forKey:(NSString *)key;
- (id)dataForKey:(NSString *)key;
@end // SingletonDataStore.m
#import "SingletonDataStore.h"
@implementation SingletonDataStore
{
NSMutableDictionary *_dataStore;
}
+ (instancetype)sharedInstance
{
static SingletonDataStore *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
- (instancetype)init
{
self = [super init];
if (self) {
_dataStore = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)setData:(id)data forKey:(NSString *)key
{
[_dataStore setObject:data forKey:key];
}
- (id)dataForKey:(NSString *)key
{
return [_dataStore objectForKey:key];
}
@end And you can use it like this: // In the app delegate
#import "SingletonDataStore.h"
// Store data
[[SingletonDataStore sharedInstance] setData:@"Hello, World!" forKey:@"greeting"]; // in the component
#import "SingletonDataStore.h"
// Retrieve data
NSString *greeting = [[SingletonDataStore sharedInstance] dataForKey:@"greeting"]; or you can use UserDefaults |
@cipolleschi Sorry, this class doesn't meet my needs. If my app has multiple RCTBridge instances simultaneously, how can my component distinguish which RCTBridge's launchOptions to use during initialization? |
There is no bridge in the New Architecture. You should not rely on the bridge as we are migrating away from it. |
Description
In Legacy architecture, developer can access RCTBridge instance in RCTViewManager to get access to the RCTBridge's bundleURL or launchOptions property
In Fabric Component,how could I access the bundleURL or launchOptions property in RCTBridge?
Steps to reproduce
1.Create an instance inherited from RCTViewComponentView
2.How can I get access to bridge.bundleURL and launchOptions?
React Native Version
0.77.0
Affected Platforms
Runtime - iOS
Areas
Fabric - The New Renderer
Output of
npx @react-native-community/cli info
Stacktrace or Logs
MANDATORY Reproducer
https://github.com/nanatlantica/RNDynamic
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: