Skip to content
Draft
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
15 changes: 11 additions & 4 deletions ios/RNSInvalidatedComponentsRegistry.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef RCT_NEW_ARCH_ENABLED

#import "RNSInvalidatedComponentsRegistry.h"
#import "RNSReactNativeVersionUtils.h"

@interface RNSInvalidatedComponentsRegistry ()
@property (nonatomic, strong) NSMutableSet<UIView<RNSViewControllerInvalidating> *> *invalidViews;
Expand All @@ -18,15 +19,21 @@ - (instancetype)init

- (void)pushForInvalidation:(UIView<RNSViewControllerInvalidating> *)view
{
[_invalidViews addObject:view];
// Backward compatibility for 0.82 RC or lower
if (facebook::react::is082PrereleaseOrLower()) {
[_invalidViews addObject:view];
}
}

- (void)flushInvalidViews
{
for (id<RNSViewControllerInvalidating> view in _invalidViews) {
[view invalidateController];
// Backward compatibility for 0.82 RC or lower
if (facebook::react::is082PrereleaseOrLower()) {
for (id<RNSViewControllerInvalidating> view in _invalidViews) {
[view invalidateController];
}
[_invalidViews removeAllObjects];
}
[_invalidViews removeAllObjects];
}

@end
Expand Down
12 changes: 8 additions & 4 deletions ios/RNSViewControllerInvalidator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

#import <React/RCTAssert.h>
#import "RNSInvalidatedComponentsRegistry.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSViewControllerInvalidating.h"

@implementation RNSViewControllerInvalidator

+ (void)invalidateViewIfDetached:(UIView<RNSViewControllerInvalidating> *_Nonnull)view
forRegistry:(RNSInvalidatedComponentsRegistry *_Nonnull)registry
{
if (view.window == nil) {
[view invalidateController];
} else {
[registry pushForInvalidation:view];
// Backward compatibility for 0.82 RC or lower
if (facebook::react::is082PrereleaseOrLower()) {
if (view.window == nil) {
[view invalidateController];
} else {
[registry pushForInvalidation:view];
}
}
}

Expand Down
21 changes: 13 additions & 8 deletions ios/bottom-tabs/RNSBottomTabsHostComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
#import "RNSDefines.h"
#import "RNSEnums.h"
#import "RNSReactBaseView.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSScreenContainer.h"

#ifdef RCT_NEW_ARCH_ENABLED
#if RCT_NEW_ARCH_ENABLED
// Starting 0.82.0, we're switching to the new impl based on RCTComponentViewProtocol.
// Additional runtime check is needed for RCs of 0.82
#if REACT_NATIVE_VERSION_MINOR <= 82
#import "RNSViewControllerInvalidating.h"
#else
#endif // REACT_NATIVE_VERSION_MINOR <= 82

#else // RCT_NEW_ARCH_ENABLED
#import <React/RCTInvalidating.h>
#endif
#endif // RCT_NEW_ARCH_ENABLED

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -26,11 +32,10 @@ NS_ASSUME_NONNULL_BEGIN
* 3. two way communication channel with React (commands & events)
*/
@interface RNSBottomTabsHostComponentView : RNSReactBaseView <
RNSScreenContainerDelegate,
#ifdef RCT_NEW_ARCH_ENABLED
RNSViewControllerInvalidating
#else
RCTInvalidating
RNSScreenContainerDelegate
#if defined(__cplusplus)
,
RNS_INVALIDATING_INTERFACE
#endif
>

Expand Down
79 changes: 59 additions & 20 deletions ios/bottom-tabs/RNSBottomTabsHostComponentView.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "RNSBottomTabsHostComponentView.h"

#import <cxxreact/ReactNativeVersion.h>

#if RCT_NEW_ARCH_ENABLED
#import <React/RCTConversions.h>
#import <React/RCTImageLoader.h>
Expand All @@ -10,8 +12,12 @@
#import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>
#import <rnscreens/RNSBottomTabsComponentDescriptor.h>
#import "RNSBottomTabsHostComponentView+RNSImageLoader.h"
#import "RNSReactNativeVersionUtils.h"

#if REACT_NATIVE_VERSION_MINOR <= 82
#import "RNSInvalidatedComponentsRegistry.h"
#import "RNSViewControllerInvalidator.h"
#endif // REACT_NATIVE_VERSION_MINOR <= 82
#endif // RCT_NEW_ARCH_ENABLED

#import "RNSBottomTabsScreenComponentView.h"
Expand Down Expand Up @@ -40,9 +46,9 @@ @implementation RNSBottomTabsHostComponentView {

RCTImageLoader *_Nullable _imageLoader;

#if RCT_NEW_ARCH_ENABLED
#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
RNSInvalidatedComponentsRegistry *_Nonnull _invalidatedComponentsRegistry;
#endif // RCT_NEW_ARCH_ENABLED
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82

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

#if RCT_NEW_ARCH_ENABLED
#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
_invalidatedComponentsRegistry = [RNSInvalidatedComponentsRegistry new];
#endif // RCT_NEW_ARCH_ENABLED
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82

_hasModifiedReactSubviewsInCurrentTransaction = NO;
_needsTabBarAppearanceUpdate = NO;
Expand All @@ -107,11 +113,26 @@ - (void)resetProps

- (void)willMoveToWindow:(UIWindow *)newWindow
{
#if RCT_NEW_ARCH_ENABLED
if (newWindow == nil) {
[_invalidatedComponentsRegistry flushInvalidViews];
#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
// Starting from 0.82.0, we're switching to the new implementation
if (facebook::react::is082PrereleaseOrLower()) {
[_invalidatedComponentsRegistry flushInvalidViews];
}
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
}
#endif // RCT_NEW_ARCH_ENABLED
}

- (void)invalidateImpl
{
// We want to run after container updates are performed (transitions etc.)
__weak auto weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
auto strongSelf = weakSelf;
if (strongSelf) {
strongSelf->_controller = nil;
}
});
}

- (void)didMoveToWindow
Expand Down Expand Up @@ -163,21 +184,24 @@ - (void)markChildUpdated
[self updateContainer];
}

#if RCT_NEW_ARCH_ENABLED

#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
#pragma mark - RNSViewControllerInvalidating

- (void)invalidateController
{
_controller = nil;
// Starting from 0.82.0, we're switching to the new implementation
if (facebook::react::is082PrereleaseOrLower()) {
[self invalidateImpl];
}
}

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

#if !RCT_NEW_ARCH_ENABLED
#pragma mark - RCTInvalidating

- (void)invalidate
Expand All @@ -189,7 +213,7 @@ - (void)invalidate
for (RNSBottomTabsScreenComponentView *subview in _reactSubviews) {
[subview invalidate];
}
_controller = nil;
[self invalidateImpl];
}

#endif
Expand Down Expand Up @@ -333,6 +357,18 @@ + (BOOL)shouldBeRecycled
return NO;
}

#if REACT_NATIVE_VERSION_MINOR >= 82

- (void)invalidate
{
// From 0.82.0, we're using a new invalidate callback
if (!facebook::react::is082PrereleaseOrLower()) {
[self invalidateImpl];
}
}

#endif // REACT_NATIVE_VERSION_MINOR >= 82

#pragma mark - RCTMountingTransactionObserving

- (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction &)transaction
Expand All @@ -341,17 +377,20 @@ - (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];
}
#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
// From 0.82.0, we're using a new invalidate callback
if (facebook::react::is082PrereleaseOrLower()) {
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];
[RNSViewControllerInvalidator invalidateViewIfDetached:self forRegistry:_invalidatedComponentsRegistry];
}
}
}
#endif // RCT_NEW_ARCH_ENABLED
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
}

- (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction &)transaction
Expand Down
21 changes: 13 additions & 8 deletions ios/bottom-tabs/RNSBottomTabsScreenComponentView.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#import <React/RCTImageSource.h>
#import "RNSBottomTabsScreenEventEmitter.h"
#import "RNSDefines.h"
#import "RNSEnums.h"
#import "RNSReactBaseView.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSSafeAreaProviding.h"
#import "RNSScrollEdgeEffectApplicator.h"
#import "RNSScrollViewBehaviorOverriding.h"

#ifdef RCT_NEW_ARCH_ENABLED
#if RCT_NEW_ARCH_ENABLED
// Starting 0.82.0, we're switching to the new impl based on RCTComponentViewProtocol.
// Additional runtime check is needed for RCs of 0.82
#if REACT_NATIVE_VERSION_MINOR <= 82
#import "RNSViewControllerInvalidating.h"
#else
#endif // REACT_NATIVE_VERSION_MINOR <= 82
#else // RCT_NEW_ARCH_ENABLED
#import <React/RCTInvalidating.h>
#endif
#endif // RCT_NEW_ARCH_ENABLED

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -22,11 +28,10 @@ NS_ASSUME_NONNULL_BEGIN
* of a particular tab.
*/
@interface RNSBottomTabsScreenComponentView : RNSReactBaseView <
RNSSafeAreaProviding,
#ifdef RCT_NEW_ARCH_ENABLED
RNSViewControllerInvalidating
#else
RCTInvalidating
RNSSafeAreaProviding
#if defined(__cplusplus)
,
RNS_INVALIDATING_INTERFACE
#endif
>

Expand Down
40 changes: 35 additions & 5 deletions ios/bottom-tabs/RNSBottomTabsScreenComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "RNSConversions.h"
#import "RNSDefines.h"
#import "RNSLog.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSSafeAreaViewNotifications.h"
#import "RNSScrollViewFinder.h"
#import "RNSScrollViewHelper.h"
Expand Down Expand Up @@ -114,13 +115,28 @@ - (nullable RNSBottomTabsHostComponentView *)reactSuperview
}
RNS_IGNORE_SUPER_CALL_END

#ifdef RCT_NEW_ARCH_ENABLED
- (void)invalidateImpl
{
// We want to run after container updates are performed (transitions etc.)
__weak auto weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
auto strongSelf = weakSelf;
if (strongSelf) {
strongSelf->_controller = nil;
}
});
}

#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82

#pragma mark - RNSViewControllerInvalidating

- (void)invalidateController
{
_controller = nil;
// Starting from 0.82.0, we're switching to the new implementation
if (facebook::react::is082PrereleaseOrLower()) {
[self invalidateImpl];
}
}

- (BOOL)shouldInvalidateOnMutation:(const facebook::react::ShadowViewMutation &)mutation
Expand All @@ -129,16 +145,18 @@ - (BOOL)shouldInvalidateOnMutation:(const facebook::react::ShadowViewMutation &)
return NO;
}

#else
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82

#if !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 +487,18 @@ + (BOOL)shouldBeRecycled
return NO;
}

#if REACT_NATIVE_VERSION_MINOR >= 82

- (void)invalidate
{
// From 0.82.0, we're using a new invalidate callback
if (!facebook::react::is082PrereleaseOrLower()) {
[self invalidateImpl];
}
}

#endif // REACT_NATIVE_VERSION_MINOR >= 82

#else

#pragma mark - LEGACY RCTComponent protocol
Expand Down
Loading
Loading