Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
12.0.0
----

This is a major release with **important breaking changes**, please see our [migration guide](https://doc.batch.com/react-native/advanced/11x-migration/) for more info on how to update your current Batch implementation.

**Expo**
- Removed Expo support from this repository. You should now use our new dedicated [Batch-Expo-Plugin](https://github.com/BatchLabs/Batch-Expo-Plugin).

**Core**
- Batch no longer requires a custom React Native CLI configuration. If `react-native.config.js` only exists for Batch, delete it or remove the `@batch.com/react-native-plugin` entry.

**Android**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas de changement pour iOS ?

Copy link
Contributor Author

@arnaud-roland arnaud-roland Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nan on a pas de breaking change coté ios, l'init du plugin était déjà manuelle et l'api à pas changée.

- The plugin is no longer auto-initialized. You should now call `RNBatchModuleImpl.initialize(application)` from `MainApplication.onCreate()` to complete setup.
- The initial state of the "Do Not Disturb" (DnD) feature is no longer read from the Android resources. You should now add a meta-data tag `batch_do_not_disturb_initial_state` to the <application> section of your `AndroidManifest`.


11.1.0
___
----

**Expo**
- Added configuration field `shouldUseNonNullableIntent` to control whether the MainActivity's `onNewIntent` method uses a nullable or non-nullable Intent parameter on Android. This is required for compatibility with AndroidX Activity 1.9+ which uses non-nullable Intent types. By default, it is set to `false` (nullable Intent) for backwards compatibility. Set it to `true` if you're using AndroidX Activity 1.9 or higher.


11.0.0
___
----

**Plugin**
* Updated Batch to 3.1
Expand Down
32 changes: 20 additions & 12 deletions android/src/main/java/com/batch/batch_rn/RNBatchModuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public class RNBatchModuleImpl {

public static final String NAME = "RNBatch";
public static final String NAME = "RNBatchModule";

private static final String PLUGIN_VERSION_ENVIRONMENT_VARIABLE = "batch.plugin.version";

Expand All @@ -66,7 +66,7 @@ public class RNBatchModuleImpl {
private static final RNBatchEventDispatcher eventDispatcher = new RNBatchEventDispatcher();

static {
System.setProperty("batch.plugin.version", PLUGIN_VERSION);
System.setProperty(PLUGIN_VERSION_ENVIRONMENT_VARIABLE, PLUGIN_VERSION);
}

private static boolean isInitialized = false;
Expand All @@ -77,31 +77,31 @@ public static Map<String, Object> getConstants() {

public static void initialize(Application application) {
if (!isInitialized) {
Log.i(LOGGER_TAG, "Initializing module");
Resources resources = application.getResources();
String packageName = application.getPackageName();
setDefaultProfileMigrations(application.getApplicationContext(), packageName);
setDefaultConfig(application.getApplicationContext(), packageName);
String batchAPIKey = resources.getString(resources.getIdentifier("BATCH_API_KEY", "string", packageName));
Batch.start(batchAPIKey);
Batch.EventDispatcher.addDispatcher(eventDispatcher);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un interet particulier de le déplacer dans setDefaultConfig ? ou c'est pour la clareté du code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouai parce que la valeur est lue via le manifest maintenant et plus par les string resources (sinon ca faisait utiliser un dangerous mod coté expo), donc du tout j'uniformise toute les valeurs lue via le manifest au même endroit (d'ou le rename de la méthode).

boolean doNotDisturbEnabled = resources.getBoolean(resources.getIdentifier("BATCH_DO_NOT_DISTURB_INITIAL_STATE", "bool", packageName));
Batch.Messaging.setDoNotDisturbEnabled(doNotDisturbEnabled);
} catch (Resources.NotFoundException e) {
Batch.Messaging.setDoNotDisturbEnabled(false);
}

application.registerActivityLifecycleCallbacks(new BatchActivityLifecycleHelper());

isInitialized = true;
} else {
Log.w(LOGGER_TAG, "Module already initialized");
}
}

public static void setDefaultProfileMigrations(Context context, String packageName) {
public static void setDefaultConfig(Context context, String packageName) {
try {
Bundle metaData = context.getPackageManager()
.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
.metaData;
if (metaData != null) {
// DnD Initial State
boolean doNotDisturbEnabled = metaData.getBoolean("batch_do_not_disturb_initial_state", false);
Batch.Messaging.setDoNotDisturbEnabled(doNotDisturbEnabled);

// Profile Migrations
boolean profileCustomIdMigrationEnabled = metaData.getBoolean("batch.profile_custom_id_migration_enabled", true);
boolean profileCustomDataMigrationEnabled = metaData.getBoolean("batch.profile_custom_data_migration_enabled", true);
EnumSet<BatchMigration> migrations = EnumSet.noneOf(BatchMigration.class);
Expand All @@ -122,6 +122,14 @@ public static void setDefaultProfileMigrations(Context context, String packageNa


public RNBatchModuleImpl(ReactApplicationContext reactContext) {
if(!isInitialized) {
Application app = (Application) reactContext.getApplicationContext();
if (app != null) {
initialize(app);
} else {
Log.e(LOGGER_TAG, "Application context is null, cannot initialize Batch module");
}
}
this.reactContext = reactContext;
this.batchInboxFetcherMap = new HashMap<>();
eventDispatcher.setReactContext(reactContext);
Expand Down
11 changes: 3 additions & 8 deletions android/src/main/java/com/batch/batch_rn/RNBatchPackage.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.batch.batch_rn;

import android.app.Application;

import androidx.annotation.Nullable;

import com.facebook.react.BaseReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.TurboReactPackage;

import java.util.Map;
import java.util.HashMap;

public class RNBatchPackage extends TurboReactPackage {

public RNBatchPackage(Application application) {
super();
RNBatchModule.initialize(application);
}
public class RNBatchPackage extends BaseReactPackage {

@Nullable
@Override
Expand Down
29 changes: 8 additions & 21 deletions android/src/newarch/java/com/batch/batch_rn/RNBatchModule.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.batch.batch_rn;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -16,8 +12,9 @@

public class RNBatchModule extends NativeRNBatchModuleSpec {

private RNBatchModuleImpl impl;
private final RNBatchModuleImpl impl;

@NonNull
@Override
public String getName() {
return RNBatchModuleImpl.NAME;
Expand All @@ -28,30 +25,20 @@ public Map<String, Object> getTypedExportedConstants() {
return RNBatchModuleImpl.getConstants();
}

public static void initialize(Application application) {
Log.d("RNBatchBridge","Init Batch Turbo Module");
RNBatchModuleImpl.initialize(application);
}

private static void setDefaultProfileMigrations(Context context, String packageName) {
RNBatchModuleImpl.setDefaultProfileMigrations(context, packageName);
}


public RNBatchModule(ReactApplicationContext reactContext) {
super(reactContext);
this.impl = new RNBatchModuleImpl(reactContext);
}

public void start() {
impl.start(getCurrentActivity());
impl.start(getReactApplicationContext().getCurrentActivity());
}

// BASE MODULE

@Override
public void optIn(Promise promise) {
impl.optIn(getCurrentActivity(), promise);
impl.optIn(getReactApplicationContext().getCurrentActivity(), promise);
}

@Override
Expand All @@ -76,7 +63,7 @@ public void updateAutomaticDataCollection(@NonNull ReadableMap dataCollection) {

@Override
public void showDebugView() {
impl.showDebugView(getCurrentActivity());
impl.showDebugView(getReactApplicationContext().getCurrentActivity());
}

@Override
Expand Down Expand Up @@ -137,7 +124,7 @@ public void push_setShowForegroundNotification(boolean enabled) { /* No effect o

@Override
public void messaging_showPendingMessage(Promise promise) {
impl.messaging_showPendingMessage(getCurrentActivity(), promise);
impl.messaging_showPendingMessage(getReactApplicationContext().getCurrentActivity(), promise);
}

@Override
Expand All @@ -147,7 +134,7 @@ public void messaging_setNotDisturbed(boolean active, Promise promise) {

@Override
public void messaging_disableDoNotDisturbAndShowPendingMessage(Promise promise) {
impl.messaging_disableDoNotDisturbAndShowPendingMessage(getCurrentActivity(), promise);
impl.messaging_disableDoNotDisturbAndShowPendingMessage(getReactApplicationContext().getCurrentActivity(), promise);
}

@Override
Expand Down Expand Up @@ -199,7 +186,7 @@ public void inbox_fetcher_fetchNextPage(String fetcherIdentifier, Promise promis

@Override
public void inbox_fetcher_displayLandingMessage(String fetcherIdentifier, String notificationIdentifier, Promise promise) {
impl.inbox_fetcher_displayLandingMessage(getCurrentActivity(), fetcherIdentifier, notificationIdentifier, promise);
impl.inbox_fetcher_displayLandingMessage(getReactApplicationContext().getCurrentActivity(), fetcherIdentifier, notificationIdentifier, promise);
}

@Override
Expand Down
1 change: 0 additions & 1 deletion app.plugin.js

This file was deleted.

15 changes: 2 additions & 13 deletions ios/RNBatch.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#import <React/RCTEventEmitter.h>
#import <Batch/Batch.h>

#define PluginVersion "ReactNative/11.1.0"

#ifdef RCT_NEW_ARCH_ENABLED
#import <RNBatchSpec/RNBatchSpec.h>
@interface RNBatch: RCTEventEmitter <NativeRNBatchModuleSpec>
#else
#import <React/RCTBridgeModule.h>
@interface RNBatch: RCTEventEmitter <RCTBridgeModule>
#endif

+ (void)start;
@interface RNBatch: NSObject

@property (nonatomic, strong) NSMutableDictionary<NSString *, BatchInboxFetcher *> *batchInboxFetcherMap;
+(void)start;

@end
39 changes: 32 additions & 7 deletions ios/RNBatch.mm
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# import <React/RCTConvert.h>
# import "RNBatch.h"
# import "RNBatchOpenedNotificationObserver.h"
# import "RNBatchEventDispatcher.h"
# import "BatchBridgeNotificationCenterDelegate.h"
#import <Batch/Batch.h>
#import <React/RCTConvert.h>
#import "RNBatch.h"
#import "RNBatchOpenedNotificationObserver.h"
#import "RNBatchEventDispatcher.h"
#import "BatchBridgeNotificationCenterDelegate.h"
#import <React/RCTEventEmitter.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import "RNBatchSpec.h"
#endif

static RNBatchEventDispatcher* dispatcher = nil;

@implementation RNBatch
#ifdef RCT_NEW_ARCH_ENABLED
#import <RNBatchSpec/RNBatchSpec.h>
@interface RNBatchModule: RCTEventEmitter <NativeRNBatchModuleSpec>
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On veut pas drop l'anciene ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est dans une autre PR

#import <React/RCTBridgeModule.h>
@interface RNBatchModule: RCTEventEmitter <RCTBridgeModule>
#endif

+ (void)start;

@property (nonatomic, strong) NSMutableDictionary<NSString *, BatchInboxFetcher *> * batchInboxFetcherMap;

@end


@implementation RNBatchModule

+ (BOOL)requiresMainQueueSetup
{
Expand Down Expand Up @@ -112,7 +129,7 @@ - (NSDictionary*)getConstants {
if (BatchSDK.isOptedOut) {
// Opt-in SDK
[BatchSDK optIn];

// Get API key and restart sdk
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *batchAPIKey = [info objectForKey:@"BatchAPIKey"];
Expand Down Expand Up @@ -959,3 +976,11 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
#endif

@end

@implementation RNBatch

+ (void) start
{
[RNBatchModule start];
}
@end
2 changes: 1 addition & 1 deletion ios/RNBatchEventDispatcher.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# import "RNBatch.h"
#import <Batch/Batch.h>

@interface RNBatchEvent : NSObject

Expand Down
19 changes: 11 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ module.exports = {
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
transform: {
'^.+\\.tsx?$': ['ts-jest', {
isolatedModules: true,
tsconfig: {
esModuleInterop: true,
skipLibCheck: true
}
}]
}
'^.+\\.tsx?$': [
'ts-jest',
{
isolatedModules: true,
tsconfig: {
esModuleInterop: true,
skipLibCheck: true,
},
},
],
},
};
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"notifications"
],
"scripts": {
"test": "jest",
"test": "jest --passWithNoTests",
"prepare": "tsc",
"bump-version": "./scripts/bump-version.sh",
"prepare": "tsc && expo-module prepare",
"doc": "typedoc",
"doc:generate": "typedoc && touch ./docs/.nojekyll",
"doc:publish": "./scripts/deploy-doc.sh",
Expand All @@ -32,8 +32,14 @@
"lint:fix": "eslint --fix \"src/**\" || true"
},
"peerDependencies": {
"expo": "*",
"react-native": "*"
},
"peerDependenciesMeta": {
"expo": {
"optional": true
}
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
Expand All @@ -45,7 +51,6 @@
"eslint": "^9.7.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"expo-module-scripts": "^3.5.2",
"globals": "^15.8.0",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
Expand Down
2 changes: 0 additions & 2 deletions plugin/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion plugin/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion plugin/jest.plugin.js

This file was deleted.

Loading