React-native-navigation: [v2][iOS] Upgraded to RN 0.59 issue with AppDelegate.m

Created on 14 Mar 2019  路  57Comments  路  Source: wix/react-native-navigation

Issue Description

I've upgraded my react-native to the stable 0.59 release but am receiving a console warning that contains the following error:

Unable to define method 'getConstants()' on NativeModule 'RNNBridgeModule'. NativeModule 'RNNBridgeModule' already has a constant or method called 'getConstants'. Please remove it.

This only occurs after installing RNN.

Steps to Reproduce / Code Snippets / Screenshots

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <ReactNativeNavigation/ReactNativeNavigation.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

  [ReactNativeNavigation bootstrap:[self sourceURLForBridge: bridge] launchOptions:launchOptions];

  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end



Environment

  • React Native Navigation version: 2.13.1
  • React Native version: 0.59.0
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): iPhone 6 (Debug)

Most helpful comment

I get the warning PerformanceLogger: Attempting to start a timespan that already exists renderApplication_React_render too. And also a slight delay in rendering. Is that known?

All 57 comments

#4853 (comment)

I tried that solution but it failed to work.
I'm also receiving messages in my console that may be related:

PerformanceLogger: Attempting to start a timespan that already exists renderApplication_React_render
PerformanceLogger: Attempting to end a timespan that has already ended renderApplication_React_render
Unbalanced calls start/end for tag 14

Not sure, any help would be awesome!

#4853 (comment)

This solution keeps me stuck on the initial screen.
Any other suggestions?

I update to rn 0.59 without any problem

#4853 (comment)

Are you using this solution? Or your AppDelegate.m looks different? Could you share with us?

#4853 (comment)

Are you using this solution? Or your AppDelegate.m looks different? Could you share with us?

Your issue appears to be different, have you made sure to re-follow the RNN instructions when installing. I'd suggest rm -rf node_modules and then re-linking RNN

Closing as this seems to be a none issue, Thanks @retyui for taking the time to help other users 鉂わ笍

@harveyconnor @retyui
With regards to this, is there any information for 0.59.3? I am having issues not being able to follow the documentation about the AppDelegate.m, where i cannot use react-native-git-upgrade. Which i quite lost in what to do.

@Seamus-melco It should work, I did from a clean install and it works. However there are a bunch of log messages that occur that might put you off, but I've chosen to ignore them for now.

Have the same warning - Unable to define method 'getConstants()' on NativeModule 'RNNBridgeModule'. Have somebody decision for these ?
Screenshot at Apr 10 14-30-22

I get the warning PerformanceLogger: Attempting to start a timespan that already exists renderApplication_React_render too. And also a slight delay in rendering. Is that known?

@Alekseyideas @pontusab I get both of those logs and my console is full of them when I launch the app.

same message on both Android and iOS:

on Android:

'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

on iOS:

[info][tid:com.facebook.react.JavaScript] 'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
[info][tid:com.facebook.react.JavaScript] 'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

Same for me

I have the same problem in combination with react-native-image-crop-picker

Same problem on Android

Same problem on Android

@guyca is there any status on fixing this?

I am having the same issue as well. New project using RN v 0.59.6. I get the error both on iOS and Android.

I copied

AppDelegate.h

and

AppDelegate.m

referenced by @retyui above to make sure there were no typo's.

Versions :

  "dependencies": {
    "react": "16.8.6",
    "react-native": "^0.59.6",
    "react-native-navigation": "^2.17.0"
  }, ...

OS: macOS Mojave

Can anyone using RN v0.59.x and NOT having this problem, respond to this issue and let us know what version of react-native-navigation you are using?

Thanks.

@Alekseyideas

Unable to define method 'getConstants()' on NativeModule 'RNNBridgeModule'. NativeModule 'RNNBridgeModule' already has a constant or method called 'getConstants'. Please remove it.

This can be resolved by commenting out the following in RNNBridgeModule.m:

RCT_EXPORT_METHOD(getConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
    resolve([Constants getConstants]);
}

Shouldn't be the intention though. Perhaps reopen @guyca?

#4853 (comment)

Are you using this solution? Or your AppDelegate.m looks different? Could you share with us?

Your issue appears to be different, have you made sure to re-follow the RNN instructions when installing. I'd suggest rm -rf node_modules and then re-linking RNN

This worked for me and I was getting the message that RNNStore.m was not being found in lib/ios

I am having the same issue as well. New project using RN v 0.59.6. I get the error both on iOS and Android.

I copied

AppDelegate.h

and

AppDelegate.m

referenced by @retyui above to make sure there were no typo's.

Versions :

  "dependencies": {
    "react": "16.8.6",
    "react-native": "^0.59.6",
    "react-native-navigation": "^2.17.0"
  }, ...

OS: macOS Mojave

Can anyone using RN v0.59.x and _NOT_ having this problem, respond to this issue and let us know what version of react-native-navigation you are using?

Thanks.

I'm having the same problem and I'm using version 0.59.4

Why is this closed? Just upgraded to RN 0.59 and getting this warning.

I have this too. Not sure what the solution is.

Also having this issue with latest react native and react native navigation.

same message on both Android and iOS:

on Android:

'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

on iOS:

[info][tid:com.facebook.react.JavaScript] 'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
[info][tid:com.facebook.react.JavaScript] 'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

@sophister wondering if you've been able to find a fix for this?

@dayaki No, I've not fixed this yet. But it seems these messages have nothing to do with react-native-navigation, I am not using this library.

I have

PerformanceLogger: Attempting to start a timespan that already exists renderApplication_React_render

When trying to push a new screen on a stack. I have not been able to push a screen on a stack currently.

After upgrade to the latest react-native from 0.57 -> to 0.59.8, I got this issue.
Everything is working (push, pop, etc.), except showModal.

I have a console log simultaneously with a "showModal" evaluation.

PerformanceLogger: Attempting to start a timespan that already exists  renderApplication_React_render  
PerformanceLogger: Attempting to end a timespan that has already ended  renderApplication_React_render

P.S. My AppDelegame.m the same as https://github.com/wix/react-native-navigation/issues/4853#issuecomment-472353418

Looks like topVC is lost somehow.

image

@guyca, @retyui take a look please on this.

With further investigations, I found that we can not access window here. It's needed to get rootViewController and take top ViewController (topVC) from it
image

Even more, in the place, where this UIApplication.sharedApplication.delegate.window should be set up - it could not, because of the same error.
image

So, based on investigation I did we could see that when I call showModal method:

  1. RNN wait for the component (modal) mount,
  2. then try to get topVC (top ViewController) to call his method presentViewController after which it should show modal
  3. got nil as topVC and method could not be called.

P.S. If I call it by myself from LLDB:

[_presentedModals addObject:viewController.navigationController ? viewController.navigationController : viewController];

Modal appears.

Ok, I found the place in my code, where I probably reset window :)
showModal now works, but I still have this error:

'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

Hope it's not crucial

Ok, I found the place in my code, where I probably reset window :)
showModal now works, but I still have this error:

'PerformanceLogger: Attempting to start a timespan that already exists ', 'renderApplication_React_render'
'PerformanceLogger: Attempting to end a timespan that has already ended ', 'renderApplication_React_render'

Hope it's not crucial

Hi @chelovekdrakon, I'm experiencing the same issue. Can you share how you got showModal to work?

Ah, I think it is because I'm calling setRoot twice but should be using setStackRoot instead for the second call.

Disregard my comments above. My problem was that we were overriding our window in AppDelegate.m after bootstrapping RNN :/

same on android

Seeing the same warning on iOS

Also seeing the same warning in IOS with react-native 0.59.9 and RRN

PerformanceLogger: Attempting to start a timespan that already exists renderApplication_React_render

How to fix? Can't find any solution

Same on iOS and Android

Following this for a while, really nobody experiences this?

Lots of people experience this but given it's just a warning we've been ignoring it.

The issue certainly should not have been closed. I doubt anyone is going to fix it since they're working on V3. I don't have the skill to fix it sadly (I tried but didn't get very far).

What I did notice is the code triggering the warning is inside React Native's NativeModules.js:

function genModule(
  config: ?ModuleConfig,
  moduleID: number,
): ?{name: string, module?: Object} {
  if (!config) {
    return null;
  }

  const [moduleName, constants, methods, promiseMethods, syncMethods] = config;
  invariant(
    !moduleName.startsWith('RCT') && !moduleName.startsWith('RK'),
    "Module name prefixes should've been stripped by the native side " +
      "but wasn't for " +
      moduleName,
  );

  if (!constants && !methods) {
    // Module contents will be filled in lazily later
    return {name: moduleName};
  }

  const module = {};
  methods &&
    methods.forEach((methodName, methodID) => {
      const isPromise =
        promiseMethods && arrayContains(promiseMethods, methodID);
      const isSync = syncMethods && arrayContains(syncMethods, methodID);
      invariant(
        !isPromise || !isSync,
        'Cannot have a method that is both async and a sync hook',
      );
      const methodType = isPromise ? 'promise' : isSync ? 'sync' : 'async';
      module[methodName] = genMethod(moduleID, methodID, methodType);
    });

  Object.assign(module, constants);

  if (module.getConstants == null) {
    module.getConstants = () => constants;
  } else {
    console.warn(
      `Unable to define method 'getConstants()' on NativeModule '${moduleName}'. NativeModule '${moduleName}' already has a constant or method called 'getConstants'. Please remove it.`,
    );
  }

  if (__DEV__) {
    BatchedBridge.createDebugLookup(moduleID, moduleName, methods);
  }

  return {name: moduleName, module};
}

For Android getConstants() function is explained here: https://facebook.github.io/react-native/docs/0.59/native-modules-android

If I look at the relevant documentation for iOS Its constants should be exported in a different way using the name: constantsToExport as explained here: https://facebook.github.io/react-native/docs/0.59/native-modules-ios

I have no clue why the implementations are named differently for iOS and Android.

The RRNBridge implementation of this project however exports a "getConstants":
https://github.com/wix/react-native-navigation/blob/0e29a03a40df26755d71c3578ca5ca554096b14c/lib/ios/RNNBridgeModule.m

RCT_EXPORT_METHOD(getConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
    resolve([Constants getConstants]);
}

My only theory is this exported method for iOS conflicts with with the method name that React Native attempts to add later.
The currently exported method should work like the developers intended to because it is exported successfully; it however prevents the "constantsToExport"-method from working. Currently this codebase doesn't have any "constantsToExport" so it doesn't break anything.

If that is true a possible fix would be to try and replace this iOS getConstants export with constantsToExport. There are quite a few caveats to watch out for when doing this and it is beyond my capability to see if that works.

I was getting these messages when following a deep link into my app.

The issue was that I had forgotten to set android:launchMode="singleTask" in AndroidManifest.xml.

I had an event listener in componentDidMount on my navigator subscribed to didFocus, but the callback for the listener wasn't firing and I was only getting those warnings in the console.

Still happening using v3 and RNN 0.60.4

Same. v3, RNN 0.60.4. ios and android

I am also getting this warning in v3 alpha 8 with RN 0.59.10

Ok it seems https://github.com/wix/react-native-navigation/issues/4861#issuecomment-485827217 temporary fixes the issue for iOS

Same, v3, RNN 0.60.4. Seeing it on Android.

@SparkleFaerieCoder try commenting the follow fragment of code in NavigationModule.java inside the RNN's library

@ReactMethod
public void getConstants(Promise promise) {
ReactApplicationContext ctx = getReactApplicationContext();
WritableMap constants = Arguments.createMap();
constants.putString(Constants.BACK_BUTTON_JS_KEY, Constants.BACK_BUTTON_ID);
constants.putDouble(Constants.BOTTOM_TABS_HEIGHT_KEY, Constants.BOTTOM_TABS_HEIGHT);
constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, StatusBarUtils.getStatusBarHeight(ctx)));
constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, pxToDp(ctx, UiUtils.getTopBarHeight(ctx)));
promise.resolve(constants);
}

Clean the project, rebuild everything and check if its still happening.

Also seeing this using 3.0.0-alpha.11 with RN 0.60.4

same issue here

If it's still happening on 3.0.0 I'd suggest opening a new ticket and referencing this one.

This ticket is closed and unlikely to be noticed by any maintainers.

Same issue for me on iOS and Android with RN 0.60.4

As for the showModal problem: we solved removing two lines from AppDelegate.m

Any update fix this issue?
It is really critical when I try to authorized page modify(maybe design), hot reloading is redirect auth page every time.

Was this page helpful?
0 / 5 - 0 ratings