Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
37 changes: 26 additions & 11 deletions integration/redux/Redux.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');
require('react-native');
const renderer = require('react-test-renderer');
const { render } = require('@testing-library/react-native');
const { Provider } = require('react-redux');
const { Navigation } = require('../../lib/src/index');

Expand Down Expand Up @@ -30,8 +30,8 @@ describe('redux support', () => {
store.reduxStore
);

const tree = renderer.create(<HOC />);
expect(tree.toJSON().children).toEqual(['no name']);
const { getByText } = render(<HOC />);
expect(getByText('no name')).toBeTruthy();
});

it('passes props into wrapped components', () => {
Expand All @@ -50,45 +50,60 @@ describe('redux support', () => {
<HOC {...props} />
))();

const tree = renderer.create(
const { getByText } = render(
<CompFromNavigation componentId="componentId" renderCountIncrement={renderCountIncrement} />
);
expect(tree.toJSON().children).toEqual(['no name']);
expect(getByText('no name')).toBeTruthy();
expect(renderCountIncrement).toHaveBeenCalledTimes(1);
});

it('rerenders as a result of an underlying state change (by selector)', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(
const { getByText, rerender } = render(
<Provider store={store.reduxStore}>
<MyConnectedComponent renderCountIncrement={renderCountIncrement} />
</Provider>
);

expect(tree.toJSON().children).toEqual(['no name']);
expect(getByText('no name')).toBeTruthy();
expect(renderCountIncrement).toHaveBeenCalledTimes(1);

store.reduxStore.dispatch({ type: 'redux.MyStore.setName', name: 'Bob' });
expect(store.selectors.getName(store.reduxStore.getState())).toEqual('Bob');
expect(tree.toJSON().children).toEqual(['Bob']);

// Re-render to see the updated state
rerender(
<Provider store={store.reduxStore}>
<MyConnectedComponent renderCountIncrement={renderCountIncrement} />
</Provider>
);
expect(getByText('Bob')).toBeTruthy();

expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});

it('rerenders as a result of an underlying state change with a new key', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(
const { queryByText, rerender } = render(
<Provider store={store.reduxStore}>
<MyConnectedComponent printAge={true} renderCountIncrement={renderCountIncrement} />
</Provider>
);

expect(tree.toJSON().children).toEqual(null);
// Initially should show nothing (null children means no text)
expect(queryByText('30')).toBeNull();
expect(renderCountIncrement).toHaveBeenCalledTimes(1);

store.reduxStore.dispatch({ type: 'redux.MyStore.setAge', age: 30 });
expect(store.selectors.getAge(store.reduxStore.getState())).toEqual(30);
expect(tree.toJSON().children).toEqual(['30']);

// Re-render to see the updated state
rerender(
<Provider store={store.reduxStore}>
<MyConnectedComponent printAge={true} renderCountIncrement={renderCountIncrement} />
</Provider>
);
expect(queryByText('30')).toBeTruthy();

expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});
Expand Down
28 changes: 18 additions & 10 deletions integration/remx/remx.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');
require('react-native');
const renderer = require('react-test-renderer');
const { render } = require('@testing-library/react-native');
const { Navigation } = require('../../lib/src/index');

describe('remx support', () => {
Expand All @@ -13,39 +13,47 @@ describe('remx support', () => {
});

it('renders normally', () => {
const tree = renderer.create(<MyConnectedComponent />);
const tree2 = renderer.create(<MyConnectedComponent />);
expect(tree.toJSON().children).toEqual(['no name']);
const { getByText } = render(<MyConnectedComponent />);
const { getByText: getByText2 } = render(<MyConnectedComponent />);
expect(getByText('no name')).toBeTruthy();
expect(getByText2('no name')).toBeTruthy();
});

it('rerenders as a result of an underlying state change (by selector)', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(
const { getByText, rerender } = render(
<MyConnectedComponent renderCountIncrement={renderCountIncrement} />
);

expect(tree.toJSON().children).toEqual(['no name']);
expect(getByText('no name')).toBeTruthy();
expect(renderCountIncrement).toHaveBeenCalledTimes(1);

store.setters.setName('Bob');
expect(store.getters.getName()).toEqual('Bob');
expect(tree.toJSON().children).toEqual(['Bob']);

// Re-render to get updated content
rerender(<MyConnectedComponent renderCountIncrement={renderCountIncrement} />);
expect(getByText('Bob')).toBeTruthy();

expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});

it('rerenders as a result of an underlying state change with a new key', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(
const { queryByText, rerender } = render(
<MyConnectedComponent printAge={true} renderCountIncrement={renderCountIncrement} />
);

expect(tree.toJSON().children).toEqual(null);
// Initially should show nothing (null children means no text)
expect(queryByText('30')).toBeNull();
expect(renderCountIncrement).toHaveBeenCalledTimes(1);

store.setters.setAge(30);
expect(store.getters.getAge()).toEqual(30);
expect(tree.toJSON().children).toEqual(['30']);

// Re-render to get updated content
rerender(<MyConnectedComponent printAge={true} renderCountIncrement={renderCountIncrement} />);
expect(queryByText('30')).toBeTruthy();

expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ModalContentLayout(context: Context?) : ReactViewGroup(context), RootView{

private val mJSTouchDispatcher = JSTouchDispatcher(this)

override fun onChildStartedNativeGesture(child: View, androidEvent: MotionEvent) {
override fun onChildStartedNativeGesture(child: View?, androidEvent: MotionEvent) {
mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, this.getEventDispatcher())
}
override fun onChildStartedNativeGesture(androidEvent: MotionEvent) {
Expand All @@ -31,7 +31,7 @@ class ModalContentLayout(context: Context?) : ReactViewGroup(context), RootView{
return UIManagerHelper.getEventDispatcher(reactContext, UIManagerType.FABRIC) ?: throw IllegalStateException("EventDispatcher for Fabric UI Manager is not found")
}

override fun handleException(t: Throwable?) {
override fun handleException(t: Throwable) {
getReactContext().handleException(RuntimeException(t))
}

Expand Down
55 changes: 36 additions & 19 deletions lib/ios/RNNAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@
#import <React/RCTSurfacePresenterStub.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>

#import <React-RCTAppDelegate/RCTAppDelegate.h>
#import <React-RCTAppDelegate/RCTReactNativeFactory.h>

#if __has_include(<React-RCTAppDelegate/RCTReactNativeFactory.h>)
#elif __has_include(<React_RCTAppDelegate/RCTReactNativeFactory.h>)
#else
// RN 0.77 support
#define RN077
#import <react/config/ReactNativeConfig.h>
#endif

#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import <React/RCTSurfacePresenter.h>
Expand All @@ -37,15 +48,17 @@ @implementation RNNAppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

#ifdef RN077
[self _setUpFeatureFlags];

// Copied from RCTAppDelegate, it private inside it
self.rootViewFactory = [self createRCTRootViewFactory];

[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;

RCTAppSetupPrepareApp(application, self.newArchEnabled);
RCTSetNewArchEnabled(TRUE);
#else
self.reactNativeFactory = [RCTReactNativeFactory new];
self.reactNativeFactory = [self.reactNativeFactory initWithDelegate:self];
#endif

RCTEnableTurboModuleInterop(YES);
RCTEnableTurboModuleInteropBridgeProxy(YES);

Expand All @@ -56,34 +69,37 @@ - (BOOL)application:(UIApplication *)application
return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
[NSException raise:@"RCTBridgeDelegate::sourceURLForBridge not implemented"
format:@"Subclasses must implement a valid sourceURLForBridge method"];
return nil;
}

- (BOOL)concurrentRootEnabled {
return true;
}



#ifdef RN077
- (RCTRootViewFactory *)createRCTRootViewFactory
{
__weak __typeof(self) weakSelf = self;
RCTBundleURLBlock bundleUrlBlock = ^{
RCTAppDelegate *strongSelf = weakSelf;
return strongSelf.bundleURL;
RCTAppDelegate *strongSelf = weakSelf;
return strongSelf.bundleURL;
};

RCTRootViewFactoryConfiguration *configuration =
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
newArchEnabled:self.newArchEnabled];
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
newArchEnabled:self.newArchEnabled];


return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
[NSException raise:@"RCTBridgeDelegate::sourceURLForBridge not implemented"
format:@"Subclasses must implement a valid sourceURLForBridge method"];
return nil;
}

- (BOOL)concurrentRootEnabled {
return true;
}

#pragma mark - Feature Flags

class RCTAppDelegateBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults {
public:
bool enableBridgelessArchitecture() override
Expand Down Expand Up @@ -113,6 +129,7 @@ - (void)_setUpFeatureFlags
facebook::react::ReactNativeFeatureFlags::override(
std::make_unique<RCTAppDelegateBridgelessFeatureFlags>());
}
#endif

@end

Loading