diff --git a/ios/react-native-navigation-sdk/NavView.mm b/ios/react-native-navigation-sdk/NavView.mm index 246b2615..ce17e08c 100644 --- a/ios/react-native-navigation-sdk/NavView.mm +++ b/ios/react-native-navigation-sdk/NavView.mm @@ -40,6 +40,7 @@ @interface NavView () @property(nonatomic, strong) NavViewController *viewController; @property(nonatomic, assign) BOOL initialized; +@property(nonatomic, copy) NSString *registeredNativeID; @end @@ -63,12 +64,20 @@ - (void)dealloc { [self unregisterView]; } +- (void)invalidate { + [self unregisterView]; + [super invalidate]; +} + - (void)unregisterView { - const auto ¤tProps = *std::static_pointer_cast(_props); + if (_registeredNativeID != nil) { + [[NavViewModule viewControllersRegistry] removeObjectForKey:_registeredNativeID]; + _registeredNativeID = nil; + } - if (!currentProps.nativeID.empty()) { - NSString *nativeIDString = [NSString stringWithUTF8String:currentProps.nativeID.c_str()]; - [[NavViewModule viewControllersRegistry] removeObjectForKey:nativeIDString]; + if (_viewController != nil) { + [_viewController cleanup]; + _viewController = nil; } } @@ -140,6 +149,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & // Register view controller with nativeID in the registry NSString *nativeIDString = [NSString stringWithUTF8String:newViewProps.nativeID.c_str()]; [NavViewModule viewControllersRegistry][nativeIDString] = _viewController; + self.registeredNativeID = nativeIDString; // If navigation session is already initialized, trigger attachment check NavModule *navModule = [NavModule sharedInstance]; diff --git a/ios/react-native-navigation-sdk/NavViewController.h b/ios/react-native-navigation-sdk/NavViewController.h index 3fd222e9..33c754f4 100644 --- a/ios/react-native-navigation-sdk/NavViewController.h +++ b/ios/react-native-navigation-sdk/NavViewController.h @@ -51,6 +51,7 @@ typedef void (^OnArrayResult)(NSArray *_Nullable result); - (void)setSpeedLimitIconEnabled:(BOOL)isEnabled; - (void)setZoomLevel:(NSNumber *)level; - (void)setNavigationViewCallbacks:(id)fn; +- (void)cleanup; - (void)setIndoorEnabled:(BOOL)isEnabled; - (void)setIndoorLevelPickerEnabled:(BOOL)isEnabled; - (void)setTrafficEnabled:(BOOL)isEnabled;