microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

Update doc for RN 0.73+? #2659

Closed pierroo closed 8 months ago

pierroo commented 8 months ago

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Steps to Reproduce

  1. use RN 0.73+
  2. MainApplication.java being replaced by MainApplication.kotlin
  3. codepush not working

Expected Behavior

doc should reflect new changes from RN 0.73+ now using kotlin

Environment

To sum up, how are we supposed to translate the following from doc into kotlin?

import com.microsoft.codepush.react.CodePush;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        ...

        // 2. Override the getJSBundleFile method in order to let
        // the CodePush runtime determine where to get the JS
        // bundle location from on each app start
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }
    };
}
benycodes commented 8 months ago

Here's how you do it in kotlin:

override fun getJSBundleFile(): String {
    return CodePush.getJSBundleFile()
}

So your MainApplication would look something like this:

// imports...
import com.microsoft.codepush.react.CodePush;

class MainApplication : Application(), ReactApplication {

  override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper(
        this,
        object : DefaultReactNativeHost(this) {
// ...

          // Add the CodePush getJSBundleFile method override
          override fun getJSBundleFile(): String {
              return CodePush.getJSBundleFile()
          }
        }
  )

  override val reactHost: ReactHost
    get() = getDefaultReactHost(this.applicationContext, reactNativeHost)

// ...
}