Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions ios/bottom-tabs/RNSBottomTabsHostComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#import "RNSReactBaseView.h"
#import "RNSScreenContainer.h"

#ifdef RCT_NEW_ARCH_ENABLED
#import "RNSViewControllerInvalidating.h"
#else
#ifndef RCT_NEW_ARCH_ENABLED
#import <React/RCTInvalidating.h>
#endif

Expand All @@ -26,10 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
* 3. two way communication channel with React (commands & events)
*/
@interface RNSBottomTabsHostComponentView : RNSReactBaseView <
RNSScreenContainerDelegate,
#ifdef RCT_NEW_ARCH_ENABLED
RNSViewControllerInvalidating
#else
RNSScreenContainerDelegate
#ifndef RCT_NEW_ARCH_ENABLED
,
RCTInvalidating
#endif
>
Expand Down
65 changes: 12 additions & 53 deletions ios/bottom-tabs/RNSBottomTabsHostComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>
#import <rnscreens/RNSBottomTabsComponentDescriptor.h>
#import "RNSBottomTabsHostComponentView+RNSImageLoader.h"
#import "RNSInvalidatedComponentsRegistry.h"
#import "RNSViewControllerInvalidator.h"
#endif // RCT_NEW_ARCH_ENABLED

#import "RNSBottomTabsScreenComponentView.h"
Expand Down Expand Up @@ -40,10 +38,6 @@ @implementation RNSBottomTabsHostComponentView {

RCTImageLoader *_Nullable _imageLoader;

#if RCT_NEW_ARCH_ENABLED
RNSInvalidatedComponentsRegistry *_Nonnull _invalidatedComponentsRegistry;
#endif // RCT_NEW_ARCH_ENABLED

// RCTViewComponentView does not expose this field, therefore we maintain
// it on our side.
NSMutableArray<RNSBottomTabsScreenComponentView *> *_reactSubviews;
Expand Down Expand Up @@ -86,10 +80,6 @@ - (void)initState
_reactSubviews = [NSMutableArray new];
_reactEventEmitter = [RNSBottomTabsHostEventEmitter new];

#if RCT_NEW_ARCH_ENABLED
_invalidatedComponentsRegistry = [RNSInvalidatedComponentsRegistry new];
#endif // RCT_NEW_ARCH_ENABLED

_hasModifiedReactSubviewsInCurrentTransaction = NO;
_needsTabBarAppearanceUpdate = NO;
}
Expand All @@ -103,17 +93,13 @@ - (void)resetProps
_tabBarTintColor = nil;
}

#pragma mark - UIView methods

- (void)willMoveToWindow:(UIWindow *)newWindow
- (void)invalidateImpl
{
#if RCT_NEW_ARCH_ENABLED
if (newWindow == nil) {
[_invalidatedComponentsRegistry flushInvalidViews];
}
#endif // RCT_NEW_ARCH_ENABLED
_controller = nil;
}

#pragma mark - UIView methods

- (void)didMoveToWindow
{
if ([self window] != nil) {
Expand Down Expand Up @@ -163,36 +149,16 @@ - (void)markChildUpdated
[self updateContainer];
}

#if RCT_NEW_ARCH_ENABLED

#pragma mark - RNSViewControllerInvalidating

- (void)invalidateController
{
_controller = nil;
}

- (BOOL)shouldInvalidateOnMutation:(const facebook::react::ShadowViewMutation &)mutation
{
return (mutation.oldChildShadowView.tag == self.tag && mutation.type == facebook::react::ShadowViewMutation::Delete);
}
#else
#ifndef RCT_NEW_ARCH_ENABLED

#pragma mark - RCTInvalidating

- (void)invalidate
{
// We assume that bottom tabs host is removed from view hierarchy **only** when
// whole component is destroyed & therefore we do the necessary cleanup here.
// If at some point that statement does not hold anymore, this cleanup
// should be moved to a different place.
for (RNSBottomTabsScreenComponentView *subview in _reactSubviews) {
[subview invalidate];
}
_controller = nil;
[self invalidateImpl];
}

#endif
#endif // !RCT_NEW_ARCH_ENABLED

#pragma mark - React events

Expand Down Expand Up @@ -309,6 +275,11 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
[super finalizeUpdates:updateMask];
}

- (void)invalidate
{
[self invalidateImpl];
}

+ (react::ComponentDescriptorProvider)componentDescriptorProvider
{
return react::concreteComponentDescriptorProvider<react::RNSBottomTabsComponentDescriptor>();
Expand All @@ -328,18 +299,6 @@ - (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction
{
_hasModifiedReactSubviewsInCurrentTransaction = NO;
[_controller reactMountingTransactionWillMount];

#if RCT_NEW_ARCH_ENABLED
for (const auto &mutation : transaction.getMutations()) {
if ([self shouldInvalidateOnMutation:mutation]) {
for (RNSBottomTabsScreenComponentView *childView in _reactSubviews) {
[RNSViewControllerInvalidator invalidateViewIfDetached:childView forRegistry:_invalidatedComponentsRegistry];
}

[RNSViewControllerInvalidator invalidateViewIfDetached:self forRegistry:_invalidatedComponentsRegistry];
}
}
#endif // RCT_NEW_ARCH_ENABLED
}

- (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction &)transaction
Expand Down
11 changes: 4 additions & 7 deletions ios/bottom-tabs/RNSBottomTabsScreenComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#import "RNSScrollEdgeEffectApplicator.h"
#import "RNSScrollViewBehaviorOverriding.h"

#ifdef RCT_NEW_ARCH_ENABLED
#import "RNSViewControllerInvalidating.h"
#else
#ifndef RCT_NEW_ARCH_ENABLED
#import <React/RCTInvalidating.h>
#endif

Expand All @@ -22,10 +20,9 @@ NS_ASSUME_NONNULL_BEGIN
* of a particular tab.
*/
@interface RNSBottomTabsScreenComponentView : RNSReactBaseView <
RNSSafeAreaProviding,
#ifdef RCT_NEW_ARCH_ENABLED
RNSViewControllerInvalidating
#else
RNSSafeAreaProviding
#ifndef RCT_NEW_ARCH_ENABLED
,
RCTInvalidating
#endif
>
Expand Down
23 changes: 9 additions & 14 deletions ios/bottom-tabs/RNSBottomTabsScreenComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,21 @@ - (nullable RNSBottomTabsHostComponentView *)reactSuperview
}
RNS_IGNORE_SUPER_CALL_END

#ifdef RCT_NEW_ARCH_ENABLED

#pragma mark - RNSViewControllerInvalidating

- (void)invalidateController
- (void)invalidateImpl
{
_controller = nil;
}

- (BOOL)shouldInvalidateOnMutation:(const facebook::react::ShadowViewMutation &)mutation
{
// For bottom tabs, Host is responsible for invalidating children.
return NO;
}

#else
#ifndef RCT_NEW_ARCH_ENABLED

#pragma mark - RCTInvalidating

- (void)invalidate
{
_controller = nil;
[self invalidateImpl];
}

#endif
#endif // !RCT_NEW_ARCH_ENABLED

#pragma mark - Events

Expand Down Expand Up @@ -469,6 +459,11 @@ + (BOOL)shouldBeRecycled
return NO;
}

- (void)invalidate
{
[self invalidateImpl];
}

#else

#pragma mark - LEGACY RCTComponent protocol
Expand Down
Loading