Skip to content

Commit 9b43ee5

Browse files
committed
Add support for android push
1 parent 23c8eb5 commit 9b43ee5

10 files changed

Lines changed: 133 additions & 41 deletions

File tree

android/build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
mavenCentral()
88
maven {
9-
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
9+
url 'https://central.sonatype.com/repository/maven-snapshots/'
1010
}
1111
}
1212

@@ -75,8 +75,13 @@ android {
7575
}
7676

7777
compileOptions {
78-
sourceCompatibility JavaVersion.VERSION_1_8
79-
targetCompatibility JavaVersion.VERSION_1_8
78+
sourceCompatibility JavaVersion.VERSION_17
79+
targetCompatibility JavaVersion.VERSION_17
80+
}
81+
82+
kotlinOptions {
83+
jvmTarget = "17"
84+
freeCompilerArgs += ["-Xskip-metadata-version-check"]
8085
}
8186

8287
}
@@ -85,7 +90,7 @@ repositories {
8590
mavenCentral()
8691
google()
8792
maven {
88-
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
93+
url 'https://central.sonatype.com/repository/maven-snapshots/'
8994
}
9095
}
9196

@@ -97,7 +102,7 @@ dependencies {
97102
//noinspection GradleDynamicVersion
98103
implementation "com.facebook.react:react-native:+"
99104
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
100-
implementation "com.movableink.sdk:inked:2.2.0"
105+
implementation "com.movableink.sdk:inked:2.3.0-SNAPSHOT"
101106
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
102107

103108
}

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RNMovableInk_kotlinVersion=1.8.0
1+
RNMovableInk_kotlinVersion=2.2.0
22
RNMovableInk_minSdkVersion=24
33
RNMovableInk_targetSdkVersion=33
44
RNMovableInk_compileSdkVersion=33

android/src/main/java/com/rnmovableink/RNMovableInkModule.kt

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,43 @@ class RNMovableInkModule(reactContext: ReactApplicationContext) :
8585
}
8686
}
8787

88-
@ReactMethod
89-
fun showInAppMessage(url: String, callback: Callback) {
90-
val activity = currentActivity
91-
if (activity is androidx.lifecycle.LifecycleOwner) {
92-
activity.lifecycleScope.launch {
93-
try {
94-
MIClient.showInAppBrowser(
95-
activity,
96-
url,
97-
listener = object : MovableInAppClient.OnUrlLoadingListener {
98-
override fun onButtonClicked(value: String) {
99-
activity.runOnUiThread {
100-
callback.invoke(value)
101-
}
102-
}
103-
}
104-
)
105-
} catch (e: Exception) {
106-
activity.runOnUiThread {
107-
callback.invoke("Error: ${e.message}")
108-
}
109-
}
110-
}
111-
}
112-
}
88+
@ReactMethod
89+
fun showInAppMessage(url: String, callback: Callback) {
90+
val activity = currentActivity
91+
if (activity is androidx.lifecycle.LifecycleOwner) {
92+
activity.lifecycleScope.launch {
93+
try {
94+
MIClient.showInAppBrowser(
95+
activity,
96+
url,
97+
listener = object : MovableInAppClient.OnUrlLoadingListener {
98+
override fun onButtonClicked(value: String) {
99+
activity.runOnUiThread {
100+
callback.invoke(value)
101+
}
102+
}
103+
}
104+
)
105+
} catch (e: Exception) {
106+
activity.runOnUiThread {
107+
callback.invoke("Error: ${e.message}")
108+
}
109+
}
110+
}
111+
}
112+
}
113113

114114
@ReactMethod
115115
fun setValidPasteboardValues(values: ReadableArray) {
116116
MIClient.validPasteboardValues(values.toStringList())
117117
}
118118

119+
@ReactMethod
120+
fun handlePushNotificationOpenedWithContent(properties: ReadableMap) {
121+
val map: Map<String, String> = properties.toHashMap().mapValues { it.value.toString() }
122+
MIClient.handlePushNotificationOpened(map)
123+
}
124+
119125
fun ReadableArray.toStringList(): List<String> {
120126
val stringList = mutableListOf<String>()
121127
for (i in 0 until size()) {

example/android/app/build.gradle

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22
apply plugin: "org.jetbrains.kotlin.android"
33
apply plugin: "com.facebook.react"
4+
apply plugin: "com.google.gms.google-services"
45

56
// import com.android.build.OutputFile
67

@@ -53,6 +54,14 @@ react {
5354
// hermesFlags = ["-O", "-output-source-map"]
5455
}
5556

57+
repositories {
58+
google()
59+
mavenCentral()
60+
maven {
61+
url 'https://central.sonatype.com/repository/maven-snapshots/'
62+
}
63+
}
64+
5665
/**
5766
* Set this to true to create four separate APKs instead of one,
5867
* one for each native architecture. This is useful if you don't
@@ -94,7 +103,7 @@ android {
94103

95104
compileSdkVersion rootProject.ext.compileSdkVersion
96105

97-
namespace "com.movableink.app"
106+
namespace "com.movableink"
98107
defaultConfig {
99108
applicationId "com.movableink.app"
100109
minSdkVersion rootProject.ext.minSdkVersion
@@ -147,13 +156,29 @@ android {
147156

148157
// }
149158
// }
159+
160+
kotlinOptions {
161+
jvmTarget = "17"
162+
freeCompilerArgs += ["-Xskip-metadata-version-check"]
163+
}
164+
165+
packagingOptions {
166+
resources {
167+
excludes += ['META-INF/versions/9/OSGI-INF/MANIFEST.MF']
168+
}
169+
}
150170
}
151171

152172
dependencies {
153173
// The version of react-native is set by the React Native Gradle Plugin
154174
implementation("com.facebook.react:react-android")
155175
implementation("com.facebook.react:flipper-integration")
156176
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
177+
178+
// Firebase for push notifications
179+
implementation platform('com.google.firebase:firebase-bom:32.7.0')
180+
implementation 'com.google.firebase:firebase-messaging'
181+
implementation project(':react-native-notifications')
157182

158183
// debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
159184
// debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"project_info": {
3+
"project_number": "957444462700",
4+
"project_id": "shoppingcart-29913",
5+
"storage_bucket": "shoppingcart-29913.firebasestorage.app"
6+
},
7+
"client": [
8+
{
9+
"client_info": {
10+
"mobilesdk_app_id": "1:957444462700:android:8ad364539a7bfe51156049",
11+
"android_client_info": {
12+
"package_name": "com.movableink.app"
13+
}
14+
},
15+
"oauth_client": [],
16+
"api_key": [
17+
{
18+
"current_key": "AIzaSyB3FB7u7uI4NvTESe3nRixswSsK1uBiX-k"
19+
}
20+
],
21+
"services": {
22+
"appinvite_service": {
23+
"other_platform_oauth_client": []
24+
}
25+
}
26+
}
27+
],
28+
"configuration_version": "1"
29+
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<uses-permission android:name="android.permission.INTERNET" />
44

55
<application
6-
android:name="com.movableink.MainApplication"
6+
android:name=".MainApplication"
77
android:label="@string/app_name"
88
android:icon="@mipmap/ic_launcher"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
1111
android:theme="@style/AppTheme">
1212
<activity
13-
android:name="com.movableink.MainActivity"
13+
android:name=".MainActivity"
1414
android:label="@string/app_name"
1515
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
1616
android:launchMode="singleTask"

example/android/app/src/main/java/com/movableink/MainApplication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.facebook.react.defaults.DefaultReactNativeHost
1212
import com.facebook.react.flipper.ReactNativeFlipper
1313
import com.facebook.soloader.SoLoader
1414
import com.rnmovableink.BuildConfig
15+
import com.wix.reactnativenotifications.RNNotificationsPackage;
1516

1617
class MainApplication : Application(), ReactApplication {
1718

example/android/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ buildscript {
55
compileSdkVersion = 34
66
targetSdkVersion = 34
77
ndkVersion = "25.1.8937393"
8+
kotlinVersion = "1.9.24"
89
}
910
repositories {
1011
google()
1112
mavenCentral()
13+
maven {
14+
url 'https://central.sonatype.com/repository/maven-snapshots/'
15+
}
1216
}
1317
dependencies {
14-
classpath("com.android.tools.build:gradle")
18+
classpath("com.android.tools.build:gradle:8.1.1")
1519
classpath("com.facebook.react:react-native-gradle-plugin")
16-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
20+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
21+
classpath("com.google.gms:google-services:4.4.0")
1722
}
1823
}
1924

example/android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ rootProject.name = 'MovableInkExample'
22
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
33
include ':app'
44
includeBuild('../node_modules/@react-native/gradle-plugin')
5+
include ':react-native-notifications'
6+
project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/lib/android/app')

example/src/App.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Notifications, type Registered } from 'react-native-notifications';
55

66
export default function App() {
77
const [link, setLink] = React.useState<string | undefined>();
8+
const [token, setToken] = React.useState<string | undefined>();
89

910
React.useEffect(() => {
1011
// If using Deferred Deep Linking, make sure to enable the app install event
@@ -22,17 +23,15 @@ export default function App() {
2223
Notifications.events().registerRemoteNotificationsRegistered(
2324
(event: Registered) => {
2425
console.log(event.deviceToken);
26+
setToken(event.deviceToken);
2527
}
2628
);
2729

2830
// Handle notifications received in foreground
2931
const foregroundSubscription =
3032
Notifications.events().registerNotificationReceivedForeground(
31-
(notification, completion) => {
32-
console.log(
33-
`Notification received in foreground: ${notification.title} : ${notification.body}`
34-
);
35-
completion({ alert: false, sound: false, badge: false });
33+
(_notification, completion) => {
34+
completion({ alert: true, sound: true, badge: false });
3635
}
3736
);
3837

@@ -51,6 +50,20 @@ export default function App() {
5150
}
5251
);
5352

53+
Notifications.getInitialNotification()
54+
.then((notification) => {
55+
if (notification) {
56+
console.log('App opened from notification:');
57+
console.log(`${JSON.stringify(notification, null, 2)}`);
58+
59+
// Handle the notification with MovableInk
60+
RNMovableInk.handlePushNotificationOpenedWithContent(
61+
notification.payload
62+
);
63+
}
64+
})
65+
.catch((err) => console.error('getInitialNotification() failed', err));
66+
5467
// Get the deep link used to open the app
5568
const getInitialURL = async () => {
5669
const universalLink = await Linking.getInitialURL();
@@ -97,6 +110,10 @@ export default function App() {
97110
return (
98111
<View style={styles.container}>
99112
<Text>Resolved Link: {link}</Text>
113+
<Text>
114+
Device Token: {'\n'}
115+
{token}
116+
</Text>
100117

101118
<Button
102119
title="Test Product Searched"
@@ -176,6 +193,8 @@ const styles = StyleSheet.create({
176193
flex: 1,
177194
alignItems: 'center',
178195
justifyContent: 'center',
196+
gap: 16,
197+
padding: 20,
179198
},
180199
box: {
181200
width: 60,

0 commit comments

Comments
 (0)