Skip to content

Commit

Permalink
feat: upgrade example to react native 0.73
Browse files Browse the repository at this point in the history
  • Loading branch information
sAleksovski committed Mar 6, 2024
1 parent 459b4ca commit d04ca20
Show file tree
Hide file tree
Showing 24 changed files with 2,776 additions and 1,471 deletions.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: ['module:@react-native/babel-preset'],
};
21 changes: 21 additions & 0 deletions docs/docs/tutorial/make-widget-configurable.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ If the configuration is cancelled when adding the widget, `WIDGET_DELETED` will

## Add a widget configuration activity class

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="Java" label="Java" default>

```java title="android/app/src/main/java/com/yourapppackage/WidgetConfigurationActivity.java"
package com.yourapppackage;

Expand All @@ -23,6 +29,21 @@ public class WidgetConfigurationActivity extends RNWidgetConfigurationActivity {
}
```

</TabItem>
<TabItem value="Kotlin" label="Kotlin">

```kotlin title="android/app/src/main/java/com/yourapppackage/WidgetConfigurationActivity.kt"
package com.yourapppackage

import com.reactnativeandroidwidget.RNWidgetConfigurationActivity

class WidgetConfigurationActivity : RNWidgetConfigurationActivity() {
}
```

</TabItem>
</Tabs>

## Update the widget provider xml file for the widget

In the widget provider we created, add `configure` and `widgetFeatures` properties.
Expand Down
25 changes: 24 additions & 1 deletion docs/docs/tutorial/register-widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ In order to register our widget so that it can be selected from the launchers wi

## Add a widget provider class

Create a new package `widget` in the native android app. Inside it create a class `Hello.java`
Create a new package `widget` in the native android app.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="Java" label="Java" default>
Inside it create a class `Hello.java`

```java title="android/app/src/main/java/com/yourapppackage/widget/Hello.java"
package com.yourapppackage.widget;
Expand All @@ -19,6 +26,22 @@ public class Hello extends RNWidgetProvider {
}
```

</TabItem>
<TabItem value="Kotlin" label="Kotlin">
Inside it create a class `Hello.kt`

```kotlin title="android/app/src/main/java/com/yourapppackage/widget/Hello.kt"
package com.yourapppackage.widget

import com.reactnativeandroidwidget.RNWidgetProvider

class Hello : RNWidgetProvider() {
}
```

</TabItem>
</Tabs>

The class **name** will be used to reference our widget.

## Create widget preview image
Expand Down
15 changes: 4 additions & 11 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

/**
Expand Down Expand Up @@ -71,7 +72,8 @@ def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion

namespace "com.androidwidgetexample"
defaultConfig {
Expand Down Expand Up @@ -115,17 +117,8 @@ android {
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("com.facebook.react:flipper-integration")

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
Expand Down
6 changes: 1 addition & 5 deletions example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
</application>
tools:ignore="GoogleAppIndexingWarning"/>
</manifest>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.androidwidgetexample

import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate

class MainActivity : ReactActivity() {

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "AndroidWidgetExample"

/**
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.androidwidgetexample

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.soloader.SoLoader

class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}

override fun getJSMainModuleName(): String = "index"

override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED

}

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

override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
}
}

This file was deleted.

Loading

0 comments on commit d04ca20

Please sign in to comment.