@applicaster/zapp-react-native-utils 16.0.0-rc.122 → 16.0.0-rc.123

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.
@@ -484,7 +484,7 @@ const MOBILE_ACTION_BUTTON_FIELDS = [
484
484
  { text: "share", value: "native_share_action" },
485
485
  { text: "downloads", value: "offline-content-button" },
486
486
  { text: "trailer", value: "trailer_action" },
487
- { text: "mute/unmute", value: "mute_unmute" },
487
+ { text: "mute/unmute", value: "mute_unmute_action" },
488
488
  ],
489
489
  },
490
490
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.122",
3
+ "version": "16.0.0-rc.123",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-rc.122",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.123",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -36,6 +36,7 @@
36
36
  "prop-types": "^15.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
+ "@applicaster/quick-brick-assets": "*",
39
40
  "@applicaster/zapp-pipes-v2-client": "*",
40
41
  "@react-native-community/netinfo": "*",
41
42
  "react": "*",
@@ -0,0 +1,18 @@
1
+ // The Jest stand-in for @applicaster/quick-brick-assets maps each existing key to itself
2
+ import { getQuickBrickAsset } from "..";
3
+
4
+ describe("getQuickBrickAsset", () => {
5
+ it("returns the asset for a plugin identifier and path", () => {
6
+ expect(
7
+ getQuickBrickAsset("mute_unmute_action", "action/flavour_1/mute.png")
8
+ ).toBe("mute_unmute_action/action/flavour_1/mute.png");
9
+ });
10
+
11
+ it("rejects unknown paths and plugin identifiers at compile time", () => {
12
+ // @ts-expect-error - no such file in mute_unmute_action
13
+ getQuickBrickAsset("mute_unmute_action", "action/flavour_9/mute.png");
14
+
15
+ // @ts-expect-error - no assets folder for this plugin
16
+ getQuickBrickAsset("unknown_plugin", "action/flavour_1/mute.png");
17
+ });
18
+ });
@@ -0,0 +1,35 @@
1
+ import assets from "@applicaster/quick-brick-assets";
2
+ import type {
3
+ QuickBrickAssetKey,
4
+ QuickBrickAssetSource,
5
+ } from "@applicaster/quick-brick-assets";
6
+
7
+ export type { QuickBrickAssetKey, QuickBrickAssetSource };
8
+
9
+ type PluginOf<K> = K extends `${infer Plugin}/${string}` ? Plugin : never;
10
+
11
+ type PathOf<K, Plugin extends string> = K extends `${Plugin}/${infer Path}`
12
+ ? Path
13
+ : never;
14
+
15
+ /** Plugin identifiers that have a folder in `@applicaster/quick-brick-assets`. */
16
+ export type QuickBrickAssetPlugin = PluginOf<QuickBrickAssetKey>;
17
+
18
+ /** Asset paths inside the given plugin's folder. */
19
+ export type QuickBrickAssetPath<Plugin extends QuickBrickAssetPlugin> = PathOf<
20
+ QuickBrickAssetKey,
21
+ Plugin
22
+ >;
23
+
24
+ /**
25
+ * Looks up an asset of `@applicaster/quick-brick-assets` by plugin identifier
26
+ * and path relative to the plugin folder, e.g.
27
+ * `getQuickBrickAsset("mute_unmute_action", "action/flavour_1/mute.png")`.
28
+ * Both arguments are checked against the package's files at compile time.
29
+ * Density variants (`@2x` / `@3x`) are not supported.
30
+ */
31
+ export const getQuickBrickAsset = <Plugin extends QuickBrickAssetPlugin>(
32
+ pluginIdentifier: Plugin,
33
+ assetPath: QuickBrickAssetPath<Plugin>
34
+ ): QuickBrickAssetSource =>
35
+ assets[`${pluginIdentifier}/${assetPath}` as QuickBrickAssetKey];
@@ -21,17 +21,45 @@ type ActionContexts<T = unknown> = {
21
21
  };
22
22
 
23
23
  /**
24
- * React Hook to subscribe to the custom action context
24
+ * A value that changes whenever a provider is added to or removed from
25
+ * `uiActionsRegistry`.
26
+ *
27
+ * Providers can register after the UI that wants them has rendered - the audio
28
+ * player registers playback speed only once its controller has state, and
29
+ * plugin-backed actions are bridged in from an effect. Put this in the
30
+ * dependency list of anything that resolves actions, so the list is re-read
31
+ * instead of being frozen at first paint.
32
+ */
33
+ export function useRegistryRevision(): number {
34
+ const [revision, setRevision] = useState(0);
35
+
36
+ useEffect(
37
+ () =>
38
+ uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
39
+ []
40
+ );
41
+
42
+ return revision;
43
+ }
44
+
45
+ /**
46
+ * Resolves a legacy action context or falls back to the UI action registry.
25
47
  * @param {*} plugId - subscribes to the context of that action plugin
26
48
  * @return {*} - global action provider context or context for specific action plugin
27
49
  */
28
50
  export function useActions<T = unknown>(plugId: string): any {
29
51
  const [logged, setLogged] = useState(false);
30
52
  const context = useContext<ActionContexts<T>>(ActionsContext);
53
+ useRegistryRevision();
54
+
31
55
  const actionContext = context?.actions?.[plugId]?.module?.context;
32
56
 
33
57
  if (plugId) {
34
58
  if (!actionContext) {
59
+ const registeredAction = uiActionsRegistry.getAction(plugId);
60
+
61
+ if (registeredAction) return registeredAction;
62
+
35
63
  if (!logged) {
36
64
  logger.warning({
37
65
  message: `useActions: Couldn't find an action for ${plugId} plugin`,
@@ -139,25 +167,3 @@ export function useEntryActionState(
139
167
 
140
168
  return { state, invokeAction };
141
169
  }
142
-
143
- /**
144
- * A value that changes whenever a provider is added to or removed from
145
- * `uiActionsRegistry`.
146
- *
147
- * Providers can register after the UI that wants them has rendered - the audio
148
- * player registers playback speed only once its controller has state, and
149
- * plugin-backed actions are bridged in from an effect. Put this in the
150
- * dependency list of anything that resolves actions, so the list is re-read
151
- * instead of being frozen at first paint.
152
- */
153
- export function useRegistryRevision(): number {
154
- const [revision, setRevision] = useState(0);
155
-
156
- useEffect(
157
- () =>
158
- uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
159
- []
160
- );
161
-
162
- return revision;
163
- }