Skip to content

Commit a17edac

Browse files
Merge pull request #6 from rn-bridge/newarch_support
Support New Architecture
2 parents 82e3180 + 16582f2 commit a17edac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4935
-2979
lines changed

README.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
# @rn-bridge/react-native-shortcuts
44

5-
Android Shortcuts and iOS Quick Actions are features that allow users to quickly access specific app
6-
functionalities directly from the home screen or app icon, enhancing user experience by providing
7-
fast access to common tasks.
5+
React native library for android shortcuts and iOS quick actions which allow users to quickly access specific app functionalities directly from the home screen or app icon, enhancing user experience by providing fast access to common tasks.
86

9-
Fully compatible with TypeScript.
7+
Fully compatible with TypeScript & Turbomodules.
108

119
## Example
1210

@@ -39,6 +37,7 @@ yarn add @rn-bridge/react-native-shortcuts
3937
## Setup
4038

4139
### iOS
40+
#### If you are using `Objective-C`
4241

4342
Add the following code to your `AppDelegate.m`
4443

@@ -52,6 +51,23 @@ Add the following code to your `AppDelegate.m`
5251
completionHandler(YES);
5352
}
5453
```
54+
#### If you are using `Swift`
55+
56+
Add the following line to your App's `Bridging-Header.h`
57+
58+
> [!IMPORTANT]
59+
> A Bridging Header is required in iOS development when you want to use Objective-C code in a Swift project.
60+
```objective-c
61+
#import "RNShortcuts.h"
62+
```
63+
64+
Add the following code to your `AppDelegate.swift`
65+
```swift
66+
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
67+
RNShortcuts.handle(shortcutItem)
68+
completionHandler(true)
69+
}
70+
```
5571

5672
### Android
5773

@@ -72,8 +88,6 @@ No setup needed
7288
| [`isShortcutSupported`](#isShortcutSupported) | Returns whether your device supports shortcuts(android), quick actions(ios). |
7389
| [`getInitialShortcutId`](#getInitialShortcutId) | If the initial app launch was triggered by a shortcut, it will give the id of that shortcut, otherwise it will give null. |
7490
| [`addOnShortcutUsedListener`](#addOnShortcutUsedListener) | If the app is in background and the app is launchced by a shortcut, it will give the id of that shortcut. |
75-
| [`removeOnShortcutUsedListener`](#removeOnShortcutUsedListener) | Removes the listener. You app no longer receives events. |
76-
7791
## Usage
7892

7993
Import
@@ -235,17 +249,23 @@ If the app is in background and the app is launchced by a shortcut, it will give
235249
shortcut.
236250

237251
```javascript
238-
const callback = (id) => {
239-
console.log('Shortcut Id:', id);
240-
};
241-
242-
Shortcuts.addOnShortcutUsedListener(callback);
243-
```
244-
245-
### removeOnShortcutUsedListener
246-
247-
```javascript
248-
Shortcuts.removeOnShortcutUsedListener();
252+
const listenerSubscription = React.useRef<null | EventSubscription>(null);
253+
254+
React.useEffect(() => {
255+
const callback = (id: string) => {
256+
console.log('Shortcut Id:', id);
257+
if (id) {
258+
Alert.alert('Shortcut Detected', `App opened with shortcut id: ${id}`);
259+
}
260+
};
261+
262+
listenerSubscription.current = Shortcuts.addOnShortcutUsedListener(callback);
263+
264+
return () => {
265+
listenerSubscription.current?.remove();
266+
listenerSubscription.current = null;
267+
}
268+
}, [])
249269
```
250270
251271
## How To Run Example App ?

android/build.gradle

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ static def supportsNamespace() {
4747
android {
4848
if (supportsNamespace()) {
4949
namespace "com.rnbridge.shortcuts"
50+
}
5051

51-
sourceSets {
52-
main {
52+
sourceSets {
53+
main {
54+
if (supportsNamespace()) {
5355
manifest.srcFile "src/main/AndroidManifestNew.xml"
5456
}
57+
if (isNewArchitectureEnabled()) {
58+
java.srcDirs += ['src/newarch']
59+
} else {
60+
java.srcDirs += ['src/oldarch']
61+
}
5562
}
5663
}
5764

@@ -60,7 +67,7 @@ android {
6067
defaultConfig {
6168
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
6269
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
63-
70+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
6471
}
6572

6673
buildTypes {
@@ -72,6 +79,11 @@ android {
7279
lintOptions {
7380
disable "GradleCompatible"
7481
}
82+
83+
buildFeatures {
84+
buildConfig true
85+
}
86+
7587
}
7688

7789
repositories {

android/gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
1212
# org.gradle.parallel=true
1313
#Sun Aug 18 23:34:54 IST 2024
14-
ReactNativeShortcuts_compileSdkVersion=33
15-
ReactNativeShortcuts_kotlinVersion=1.9.24
16-
ReactNativeShortcuts_minSdkVersion=21
17-
ReactNativeShortcuts_ndkversion=26.1.10909125
18-
ReactNativeShortcuts_targetSdkVersion=33
19-
android.useAndroidX=true
14+
ReactNativeShortcuts_compileSdkVersion=34
15+
ReactNativeShortcuts_kotlinVersion=2.0.21
16+
ReactNativeShortcuts_minSdkVersion=24
17+
ReactNativeShortcuts_ndkversion=27.1.12297006
18+
ReactNativeShortcuts_targetSdkVersion=34
19+
android.useAndroidX=true

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

android/gradlew

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -84,7 +86,8 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90+
' "$PWD" ) || exit
8891

8992
# Use the maximum available, or set MAX_FD != -1 to use that value.
9093
MAX_FD=maximum

android/gradlew.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
package com.rnbridge.shortcuts
22

3-
import com.facebook.react.ReactPackage
3+
import com.facebook.react.BaseReactPackage
44
import com.facebook.react.bridge.NativeModule
55
import com.facebook.react.bridge.ReactApplicationContext
6+
import com.facebook.react.module.model.ReactModuleInfo
7+
import com.facebook.react.module.model.ReactModuleInfoProvider
68
import com.facebook.react.uimanager.ViewManager
79

8-
9-
class RNShortcutsPackage : ReactPackage {
10+
class RNShortcutsPackage : BaseReactPackage() {
1011
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
1112
return listOf(RNShortcutsModule(reactContext))
1213
}
1314

1415
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
1516
return emptyList()
1617
}
18+
19+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
20+
return when (name) {
21+
"RNShortcuts" -> RNShortcutsModule(reactContext)
22+
else -> null
23+
}
24+
}
25+
26+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
27+
return ReactModuleInfoProvider {
28+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
29+
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
30+
moduleInfos["RNShortcuts"] = ReactModuleInfo(
31+
"RNShortcuts",
32+
"RNShortcuts",
33+
false,
34+
false,
35+
false,
36+
isTurboModule
37+
)
38+
moduleInfos
39+
}
40+
}
1741
}

0 commit comments

Comments
 (0)