Skip to content

Commit 58fc99c

Browse files
Merge pull request #7 from rn-bridge/update_listener
Update listeners
2 parents a17edac + bfd9c8c commit 58fc99c

File tree

19 files changed

+82
-216
lines changed

19 files changed

+82
-216
lines changed

README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,11 @@ Response:
129129
Supported options:
130130
| Key | Platform | Required | Description |
131131
| --- | --- | --- | --- |
132-
| `id` | Both | Yes | A required, app-specific string that you employ to identify the
133-
shortcut. |
132+
| `id` | Both | Yes | A required, app-specific string that you employ to identify the shortcut. |
134133
| `title` | Both | Yes | The required, user-visible title for the Home Screen shortcut. |
135-
| `longLabel` | Android | No | An extended phrase that describes the shortcut's purpose. If
136-
there's enough space, the launcher displays this value instead of title. When possible, limit this
137-
long description to 25 characters. |
138-
| `subtitle` | iOS | No | The user-visible subtitle for the Home Screen dynamic quick
139-
action. |
140-
| `iconName` | Both | No | The icon for the Home Screen shortcut. Icon name should be the
141-
name of your iOS asset or Android drawable.
142-
Refer [iOS](https://developer.apple.com/documentation/xcode/managing-assets-with-asset-catalogs) [Android](https://developer.android.com/studio/write/resource-manager)
143-
resource addition. |
134+
| `longLabel` | Android | No | An extended phrase that describes the shortcut's purpose. If there's enough space, the launcher displays this value instead of title. When possible, limit this long description to 25 characters. |
135+
| `subtitle` | iOS | No | The user-visible subtitle for the Home Screen dynamic quick action. |
136+
| `iconName` | Both | No | The icon for the Home Screen shortcut. Icon name should be the name of your iOS asset or Android drawable. Refer [iOS](https://developer.apple.com/documentation/xcode/managing-assets-with-asset-catalogs) & [Android](https://developer.android.com/studio/write/resource-manager) resource addition. |
144137

145138
### updateShortcut
146139

@@ -166,15 +159,9 @@ Supported options:
166159
| --- | --- | --- | --- |
167160
| `id` | Both | Yes | The shortcut id which you want to update. |
168161
| `title` | Both | Yes | The required, user-visible title for the Home Screen shortcut. |
169-
| `longLabel` | Android | No | An extended phrase that describes the shortcut's purpose. If
170-
there's enough space, the launcher displays this value instead of title. When possible, limit this
171-
long description to 25 characters. |
172-
| `subtitle` | iOS | No | The user-visible subtitle for the Home Screen dynamic quick
173-
action. |
174-
| `iconName` | Both | No | The icon for the Home Screen shortcut. Icon name should be the
175-
name of your iOS asset or Android drawable.
176-
Refer [iOS](https://developer.apple.com/documentation/xcode/managing-assets-with-asset-catalogs) [Android](https://developer.android.com/studio/write/resource-manager)
177-
resource addition. |
162+
| `longLabel` | Android | No | An extended phrase that describes the shortcut's purpose. If there's enough space, the launcher displays this value instead of title. When possible, limit this long description to 25 characters. |
163+
| `subtitle` | iOS | No | The user-visible subtitle for the Home Screen dynamic quick action. |
164+
| `iconName` | Both | No | The icon for the Home Screen shortcut. Icon name should be the name of your iOS asset or Android drawable. Refer [iOS](https://developer.apple.com/documentation/xcode/managing-assets-with-asset-catalogs) & [Android](https://developer.android.com/studio/write/resource-manager) resource addition. |
178165

179166
### removeShortcut
180167

android/src/newarch/com/rnbridge/shortcuts/RNShortcutsModule.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.core.content.pm.ShortcutManagerCompat
1010
import androidx.core.graphics.drawable.IconCompat
1111
import com.facebook.react.bridge.ActivityEventListener
1212
import com.facebook.react.bridge.Arguments
13-
import com.facebook.react.bridge.Callback
1413
import com.facebook.react.bridge.Promise
1514
import com.facebook.react.bridge.ReactApplicationContext
1615
import com.facebook.react.bridge.ReadableMap
@@ -148,7 +147,9 @@ class RNShortcutsModule(reactContext: ReactApplicationContext) :
148147
}
149148

150149
private fun sendEvent(id: String) {
151-
emitOnShortcutUsed(id)
150+
context
151+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
152+
.emit("onShortcutUsed", id)
152153
}
153154

154155
override fun onActivityResult(a: Activity?, b: Int, c: Int, d: Intent?) {}

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ PODS:
12101210
- React-jsiexecutor
12111211
- React-RCTFBReactNativeSpec
12121212
- ReactCommon/turbomodule/core
1213-
- react-native-shortcuts (0.6.0):
1213+
- react-native-shortcuts (0.7.0):
12141214
- DoubleConversion
12151215
- glog
12161216
- hermes-engine
@@ -1772,7 +1772,7 @@ SPEC CHECKSUMS:
17721772
React-logger: e7eeebaed32b88dcc29b10901aa8c5822dc397c4
17731773
React-Mapbuffer: 73dd1210c4ecf0dfb4e2d4e06f2a13f824a801a9
17741774
React-microtasksnativemodule: d03753688e2abf135edcd4160ab3ce7526da8b0d
1775-
react-native-shortcuts: ea96a65e84666646e20acbc74a11e13ae5b6fc7f
1775+
react-native-shortcuts: a39f3dda191feaadecbb1d3d333961da8b395db1
17761776
React-nativeconfig: cb207ebba7cafce30657c7ad9f1587a8f32e4564
17771777
React-NativeModulesApple: 8411d548b1ad9d2b3e597beb9348e715c8020e0c
17781778
React-perflogger: c4c3b7c18f8a50cdbe2bcdd2f15705ba029a5a02

ios/RNShortcuts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
NS_ASSUME_NONNULL_BEGIN
1010

1111
#ifdef RCT_NEW_ARCH_ENABLED
12-
@interface RNShortcuts : NativeShortcutsSpecBase <NativeShortcutsSpec>
12+
@interface RNShortcuts : RCTEventEmitter <NativeShortcutsSpec>
1313
#else
1414
@interface RNShortcuts : RCTEventEmitter <RCTBridgeModule>
1515
#endif

ios/RNShortcuts.mm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ - (void)updateShortcut:(JS::NativeShortcuts::ShortcutParamsType &)params resolve
106106
+ (void)handleShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem {
107107
RNShortcutsImpl.shortcutItemType = shortcutItem.type;
108108
if (sharedInstance) {
109-
#ifdef RCT_NEW_ARCH_ENABLED
110-
[sharedInstance emitOnShortcutUsed: shortcutItem.type];
111-
#else
112-
[sharedInstance sendEventWithName:@"onShortcutUsed" body:shortcutItem.type];
113-
#endif
109+
[sharedInstance sendEventWithName:@"onShortcutUsed" body:shortcutItem.type];
114110
}
115111
}
116112

lib/commonjs/index.js

Lines changed: 19 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/commonjs/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/module/index.js

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/module/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/typescript/commonjs/src/NativeShortcuts.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type TurboModule } from 'react-native';
2-
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
32
export interface ShortcutResponseType {
43
id: string;
54
title: string;
@@ -18,7 +17,8 @@ export interface Spec extends TurboModule {
1817
isShortcutExists(id: string): Promise<boolean>;
1918
isShortcutSupported(): Promise<boolean>;
2019
getInitialShortcutId(): Promise<string>;
21-
readonly onShortcutUsed: EventEmitter<string>;
20+
addListener: (eventType: string) => void;
21+
removeListeners: (count: number) => void;
2222
}
2323
declare const _default: Spec;
2424
export default _default;

0 commit comments

Comments
 (0)