如何在React Native Android本机代码中获取应用程序实例?

Mud*_*ire 6 android reactjs react-native

我正在开发一个反应本机 Android 应用程序。我想获取当前的 ReactNativeApplication 实例,人们用 来获取应用程序实例com.facebook.react.common.ApplicationHolder.getApplication(),但现在这个方法已被弃用,那么现在有其他选择吗?

Jac*_*nkr 0

我也有同样的问题。目前我正在使用类似的东西

// imports up here

let app; // make a global variable

function calledFromiOSFramework() {
    // the 'this' is not longer bound to the 'App'
    console.log(app); // a working reference to 'App'
}

export default class App extends Component {
    app = this;

    render() {
        return(/*...*/)
    }
}
Run Code Online (Sandbox Code Playgroud)

没什么优雅的,但它有效。