Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create react-native-appboy-sdk plugin #50

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-native-appboy-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require('expo-module-scripts/eslintrc.base.js');
50 changes: 50 additions & 0 deletions packages/react-native-appboy-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# @config-plugins/react-native-appboy-sdk

Expo Config Plugin to auto configure [`react-native-appboy-sdk`](https://www.npmjs.com/package/react-native-appboy-sdk) when the native code is generated (`expo prebuild`).

## Expo installation

> Tested against Expo SDK 42

This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).

- First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).

```sh
expo install react-native-appboy-sdk @config-plugins/react-native-appboy-sdk
```

After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:

```json
{
"expo": {
"plugins": ["@config-plugins/react-native-appboy-sdk"]
}
}
```

Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.

## API

The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.

- `foobar` (_boolean_): Does XYZ. Default `false`.

#### Example

```json
{
"expo": {
"plugins": [
[
"@config-plugins/react-native-appboy-sdk",
{
// props ...
}
]
]
}
}
```
3 changes: 3 additions & 0 deletions packages/react-native-appboy-sdk/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Gradle files
.gradle/
build/
52 changes: 52 additions & 0 deletions packages/react-native-appboy-sdk/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

group = 'host.exp.exponent'
version = '0.0.1'

buildscript {
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

repositories {
mavenCentral()
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
}
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 30)

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 30)
versionCode 1
versionName '1.1.0'
}
lintOptions {
abortOnError false
}
}

dependencies {
implementation project(':expo-modules-core')
implementation project(':react-native-appboy-sdk')

//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<manifest package="expo.modules.adapters.braze">
<service
android:name="com.braze.push.BrazeFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package expo.modules.adapters.braze

import android.app.Application
import android.content.Context
import expo.modules.core.interfaces.ApplicationLifecycleListener
import com.appboy.AppboyLifecycleCallbackListener

class BrazeApplicationLifecycleListener(context: Context?) : ApplicationLifecycleListener {
var context = context

override fun onCreate(application: Application) {
super.onCreate(application)
application.registerActivityLifecycleCallbacks(AppboyLifecycleCallbackListener())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package expo.modules.adapters.braze

import android.content.Context
import expo.modules.core.interfaces.ApplicationLifecycleListener
import expo.modules.core.interfaces.Package
import expo.modules.core.interfaces.ReactActivityLifecycleListener

class BrazePackage : Package {
override fun createApplicationLifecycleListeners(context: Context?): List<ApplicationLifecycleListener> {
return listOf(BrazeApplicationLifecycleListener(context))
}
override fun createReactActivityLifecycleListeners(activityContext: Context): List<ReactActivityLifecycleListener> {
return listOf(BrazeReactActivityLifecycleListener(activityContext))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package expo.modules.adapters.braze

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import expo.modules.core.interfaces.ReactActivityLifecycleListener


class BrazeReactActivityLifecycleListener(activityContext: Context) : ReactActivityLifecycleListener {
private var activity: Activity? = null
override fun onCreate(activity: Activity, savedInstanceState: Bundle?) {
this.activity = activity
}

override fun onNewIntent(intent: Intent?): Boolean {
var result = super.onNewIntent(intent)
activity?.intent = intent
return result
}
}
1 change: 1 addition & 0 deletions packages/react-native-appboy-sdk/app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./build/withReactNativeAppboySdk");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions packages/react-native-appboy-sdk/build/withReactNativeAppboySdk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/react-native-appboy-sdk/expo-module.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"platforms": [
"android",
"ios"
],
"ios": {
"appDelegateSubscribers": ["BrazeAppDelegate"]
}
}
33 changes: 33 additions & 0 deletions packages/react-native-appboy-sdk/ios/ExpoAdapterBraze.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))

Pod::Spec.new do |s|
s.name = 'ExpoAdapterBraze'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']
s.platform = :ios, '12.0'
s.swift_version = '5.4'
s.source = { git: 'https://github.com/expo/config-plugins.git' }
s.static_framework = true

s.dependency 'ExpoModulesCore'
s.dependency 'React-Core'
s.dependency 'react-native-appboy-sdk'

# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES'
}

if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
s.source_files = "#{s.name}/**/*.h"
s.vendored_frameworks = "#{s.name}.xcframework"
else
s.source_files = "#{s.name}/**/*.{h,m,swift}"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Appboy_iOS_SDK
import ExpoModulesCore
import SystemConfiguration

public class BrazeAppDelegate: ExpoAppDelegateSubscriber {
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let braze = Bundle.main.object(forInfoDictionaryKey: "Braze")
Appboy.start(withApiKey: braze.ApiKey, in:application, withLaunchOptions:launchOptions)
return true
}

public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Appboy.sharedInstance()?.registerDeviceToken(deviceToken)
}

public func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
Appboy.sharedInstance()?.register(application,
didReceiveRemoteNotification: userInfo,
fetchCompletionHandler: completionHandler)
}

// public func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// return false
// }

// public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// return false
// }
}
Loading