react-native-ble-nitro 1.0.0-beta.7 → 1.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,9 @@ android {
36
36
  }
37
37
  }
38
38
 
39
+ // Apply Nitro autolinking
40
+ apply from: '../nitrogen/generated/android/BleNitro+autolinking.gradle'
41
+
39
42
  dependencies {
40
43
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41
44
  implementation 'androidx.core:core-ktx:1.9.0'
@@ -4,7 +4,7 @@
4
4
  * Copyright © 2025 Zyke (https://zyke.co)
5
5
  */
6
6
 
7
- package co.zyke.ble
7
+ package com.margelo.nitro.co.zyke.ble
8
8
 
9
9
  import android.bluetooth.*
10
10
  import android.bluetooth.le.*
@@ -16,6 +16,7 @@ import android.util.Log
16
16
  import androidx.core.content.ContextCompat
17
17
  import com.facebook.react.bridge.ReactApplicationContext
18
18
  import com.margelo.nitro.co.zyke.ble.HybridBleManagerSpec
19
+ import com.margelo.nitro.NitroModules
19
20
  import kotlinx.coroutines.*
20
21
  import kotlinx.coroutines.channels.Channel
21
22
  import no.nordicsemi.android.ble.BleManager
@@ -33,7 +34,12 @@ import com.margelo.nitro.co.zyke.ble.*
33
34
  * Core BLE Manager implementation using Android BLE APIs
34
35
  * Implements the HybridBleManagerSpec interface generated by Nitro
35
36
  */
36
- class BleNitroBleManager(private val context: ReactApplicationContext) : HybridBleManagerSpec {
37
+ class BleNitroBleManager : HybridBleManagerSpec {
38
+
39
+ // Get context from Nitro's context system
40
+ private val context: ReactApplicationContext by lazy {
41
+ NitroModules.getReactApplicationContext()
42
+ }
37
43
 
38
44
  companion object {
39
45
  private const val TAG = "BleNitroBleManager"
@@ -23,14 +23,21 @@ Pod::Spec.new do |s|
23
23
  # iOS frameworks
24
24
  s.frameworks = "CoreBluetooth"
25
25
 
26
- # Build settings
27
- s.pod_target_xcconfig = {
26
+ # Apply Nitro autolinking
27
+ load '../nitrogen/generated/ios/BleNitro+autolinking.rb'
28
+ add_nitrogen_files(s)
29
+
30
+ # Base build settings (will be merged with autolinking settings)
31
+ base_xcconfig = {
28
32
  'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) FOLLY_NO_CONFIG FOLLY_MOBILE=1 FOLLY_USE_LIBCPP=1',
29
- 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
30
33
  'CLANG_CXX_LIBRARY' => 'libc++',
31
34
  'OTHER_CPLUSPLUSFLAGS' => '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
32
35
  }
33
36
 
37
+ # Merge with existing pod_target_xcconfig from autolinking
38
+ current_xcconfig = s.pod_target_xcconfig || {}
39
+ s.pod_target_xcconfig = base_xcconfig.merge(current_xcconfig)
40
+
34
41
  s.user_target_xcconfig = {
35
42
  'OTHER_LDFLAGS' => '-lc++'
36
43
  }
@@ -335,6 +335,7 @@ public class BleNitroBleManager: HybridBleManagerSpec, CBCentralManagerDelegate
335
335
  public func centralManagerDidUpdateState(_ central: CBCentralManager) {
336
336
  let state = mapCBManagerState(central.state)
337
337
  stateChangeListener?(state)
338
+ print("BleNitro: Central manager state changed to: \(central.state.rawValue)")
338
339
  }
339
340
 
340
341
  public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) {
@@ -556,14 +557,6 @@ extension BleNitroBleManager: CBPeripheralDelegate {
556
557
  }
557
558
  }
558
559
 
559
- public func centralManagerDidUpdateState(_ central: CBCentralManager) {
560
- let newState = convertCBManagerStateToState(central.state)
561
-
562
- // Notify state change listener if available
563
- stateChangeListener?(newState)
564
-
565
- print("BleNitro: Central manager state changed to: \(central.state.rawValue)")
566
- }
567
560
  }
568
561
 
569
562
  /**
@@ -20,14 +20,5 @@ public class BleNitroModule: NSObject {
20
20
  return [:]
21
21
  }
22
22
 
23
- override init() {
24
- super.init()
25
- // Register the BleManager HybridObject
26
- HybridObjectRegistry.registerHybridObjectConstructor(
27
- name: "BleManager",
28
- constructor: {
29
- return BleNitroBleManager()
30
- }
31
- )
32
- }
23
+ // Autolinking handles the Nitro registration automatically
33
24
  }
package/nitro.json CHANGED
@@ -8,7 +8,12 @@
8
8
  "androidNamespace": ["co", "zyke", "ble"],
9
9
  "androidCxxLibName": "BleNitro"
10
10
  },
11
- "autolinking": {},
11
+ "autolinking": {
12
+ "BleManager": {
13
+ "swift": "BleNitroBleManager",
14
+ "kotlin": "BleNitroBleManager"
15
+ }
16
+ },
12
17
  "ignorePaths": [
13
18
  "**/node_modules"
14
19
  ]
@@ -24,6 +24,8 @@
24
24
  #include "JHybridDescriptorSpec.hpp"
25
25
  #include "JHybridDeviceSpec.hpp"
26
26
  #include "JHybridServiceSpec.hpp"
27
+ #include <NitroModules/JNISharedPtr.hpp>
28
+ #include <NitroModules/DefaultConstructableObject.hpp>
27
29
 
28
30
  namespace margelo::nitro::co::zyke::ble {
29
31
 
@@ -45,7 +47,15 @@ int initialize(JavaVM* vm) {
45
47
  margelo::nitro::co::zyke::ble::JHybridServiceSpec::registerNatives();
46
48
 
47
49
  // Register Nitro Hybrid Objects
48
-
50
+ HybridObjectRegistry::registerHybridObjectConstructor(
51
+ "BleManager",
52
+ []() -> std::shared_ptr<HybridObject> {
53
+ static DefaultConstructableObject<JHybridBleManagerSpec::javaobject> object("com/margelo/nitro/co/zyke/ble/BleNitroBleManager");
54
+ auto instance = object.create();
55
+ auto globalRef = jni::make_global(instance);
56
+ return JNISharedPtr::make_shared_from_jni<JHybridBleManagerSpec>(globalRef);
57
+ }
58
+ );
49
59
  });
50
60
  }
51
61
 
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// BleNitroAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "BleNitro-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridBleManagerSpecSwift.hpp"
14
+
15
+ @interface BleNitroAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation BleNitroAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::co::zyke::ble;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "BleManager",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ std::shared_ptr<margelo::nitro::co::zyke::ble::HybridBleManagerSpec> hybridObject = BleNitro::BleNitroAutolinking::createBleManager();
28
+ return hybridObject;
29
+ }
30
+ );
31
+ }
32
+
33
+ @end
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// BleNitroAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ public final class BleNitroAutolinking {
9
+ public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
10
+
11
+ /**
12
+ * Creates an instance of a Swift class that implements `HybridBleManagerSpec`,
13
+ * and wraps it in a Swift class that can directly interop with C++ (`HybridBleManagerSpec_cxx`)
14
+ *
15
+ * This is generated by Nitrogen and will initialize the class specified
16
+ * in the `"autolinking"` property of `nitro.json` (in this case, `BleNitroBleManager`).
17
+ */
18
+ public static func createBleManager() -> bridge.std__shared_ptr_margelo__nitro__co__zyke__ble__HybridBleManagerSpec_ {
19
+ let hybridObject = BleNitroBleManager()
20
+ return { () -> bridge.std__shared_ptr_margelo__nitro__co__zyke__ble__HybridBleManagerSpec_ in
21
+ let __cxxWrapped = hybridObject.getCxxWrapper()
22
+ return __cxxWrapped.getCxxPart()
23
+ }()
24
+ }
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "High-performance React Native BLE library built on Nitro Modules - drop-in replacement for react-native-ble-plx",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -3,7 +3,7 @@ module.exports = {
3
3
  platforms: {
4
4
  android: {
5
5
  sourceDir: './android',
6
- packageImportPath: 'import co.zyke.ble.BleNitroPackage;',
6
+ // No packageImportPath needed - autolinking handles registration
7
7
  },
8
8
  ios: {
9
9
  project: './ios/BleNitro.xcodeproj',
@@ -1,37 +0,0 @@
1
- /**
2
- * BleNitroPackage.kt
3
- * React Native BLE Nitro - Android Package Registration
4
- * Copyright © 2025 Zyke (https://zyke.co)
5
- */
6
-
7
- package co.zyke.ble
8
-
9
- import com.facebook.react.ReactPackage
10
- import com.facebook.react.bridge.NativeModule
11
- import com.facebook.react.bridge.ReactApplicationContext
12
- import com.facebook.react.uimanager.ViewManager
13
- import com.margelo.nitro.HybridObjectRegistry
14
-
15
- /**
16
- * React Native package for BLE Nitro
17
- * Registers the HybridObject manually through the registry
18
- */
19
- class BleNitroPackage : ReactPackage {
20
-
21
- companion object {
22
- init {
23
- // Register the BleManager HybridObject
24
- HybridObjectRegistry.registerHybridObjectConstructor("BleManager") { context ->
25
- BleNitroBleManager(context as ReactApplicationContext)
26
- }
27
- }
28
- }
29
-
30
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
31
- return emptyList() // Nitro modules don't use traditional NativeModules
32
- }
33
-
34
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
35
- return emptyList()
36
- }
37
- }