@applicaster/zapp-react-native-utils 15.0.0-alpha.2864324112 → 15.0.0-alpha.3110015001
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.
- package/actionUtils/index.ts +7 -0
- package/appUtils/focusManagerAux/utils/index.ts +10 -2
- package/componentsUtils/index.ts +8 -0
- package/package.json +2 -2
- package/pluginUtils/index.ts +4 -5
- package/reactHooks/casting/index.ts +1 -0
- package/reactHooks/casting/useIsCasting.tsx +57 -0
- package/reactHooks/resolvers/useComponentResolver.ts +2 -2
- package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +45 -0
- package/refreshUtils/RefreshCoordinator/index.ts +34 -5
|
@@ -142,6 +142,10 @@ export const isTabsScreenOnContentFocused = (node) => {
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
export const isCurrentFocusOnMenu = (node) => {
|
|
145
|
+
if (isNil(node)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
145
149
|
if (isRoot(node)) {
|
|
146
150
|
return false;
|
|
147
151
|
}
|
|
@@ -154,10 +158,14 @@ export const isCurrentFocusOnMenu = (node) => {
|
|
|
154
158
|
return false;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
return isCurrentFocusOnMenu(node
|
|
161
|
+
return isCurrentFocusOnMenu(node?.parent);
|
|
158
162
|
};
|
|
159
163
|
|
|
160
164
|
export const isCurrentFocusOnContent = (node) => {
|
|
165
|
+
if (isNil(node)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
161
169
|
if (isRoot(node)) {
|
|
162
170
|
return false;
|
|
163
171
|
}
|
|
@@ -170,7 +178,7 @@ export const isCurrentFocusOnContent = (node) => {
|
|
|
170
178
|
return true;
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
return isCurrentFocusOnContent(node
|
|
181
|
+
return isCurrentFocusOnContent(node?.parent);
|
|
174
182
|
};
|
|
175
183
|
|
|
176
184
|
export const isCurrentFocusOn = (id, node) => {
|
package/componentsUtils/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { last } from "@applicaster/zapp-react-native-utils/utils";
|
|
2
|
+
|
|
1
3
|
const GROUP = "group-qb";
|
|
2
4
|
const GROUP_INFO = "group-info-qb";
|
|
3
5
|
const GROUP_INFO_OLD = "group-info";
|
|
@@ -29,6 +31,12 @@ export const isFirstComponentGallery = (
|
|
|
29
31
|
return isGallery(components?.[0]);
|
|
30
32
|
};
|
|
31
33
|
|
|
34
|
+
export const isLastComponentGallery = (
|
|
35
|
+
components: ZappUIComponent[]
|
|
36
|
+
): boolean => {
|
|
37
|
+
return isGallery(last(components));
|
|
38
|
+
};
|
|
39
|
+
|
|
32
40
|
export const isGroup = (item): boolean => item?.component_type === GROUP;
|
|
33
41
|
|
|
34
42
|
export const isEmptyGroup = (item): boolean =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "15.0.0-alpha.
|
|
3
|
+
"version": "15.0.0-alpha.3110015001",
|
|
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": "15.0.0-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "15.0.0-alpha.3110015001",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
package/pluginUtils/index.ts
CHANGED
|
@@ -30,10 +30,7 @@ export function getComponentModule({
|
|
|
30
30
|
components: ComponentsMap;
|
|
31
31
|
plugins: Plugin[] | QuickBrickPlugin[];
|
|
32
32
|
}) {
|
|
33
|
-
const component =
|
|
34
|
-
R.prop(R.__, components),
|
|
35
|
-
toPascalCase
|
|
36
|
-
)(componentType);
|
|
33
|
+
const component = components[toPascalCase(componentType)];
|
|
37
34
|
|
|
38
35
|
if (component) {
|
|
39
36
|
return component;
|
|
@@ -60,7 +57,9 @@ export function findComponentByType({
|
|
|
60
57
|
? R.compose(...R.reverse(decorators))
|
|
61
58
|
: decorators;
|
|
62
59
|
|
|
63
|
-
const
|
|
60
|
+
const module = getComponentModule({ componentType, components, plugins });
|
|
61
|
+
|
|
62
|
+
const component = module?.Component || module;
|
|
64
63
|
|
|
65
64
|
return R.unless(R.isNil, applyDecorators)(component);
|
|
66
65
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useIsCasting } from "./useIsCasting";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
3
|
+
import { useAppState } from "@applicaster/zapp-react-native-utils/reactHooks/app";
|
|
4
|
+
import { isApplePlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
5
|
+
|
|
6
|
+
const CHROMECAST_IDENTIFIER = "quick-brick-chromecast-action";
|
|
7
|
+
|
|
8
|
+
const fakeEntry: any = {
|
|
9
|
+
title: "Chromecast use is casting fake entry",
|
|
10
|
+
id: "quick-brick-use-is-casting-fake-entry",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the cast action state connection status, does not update when app is in background on Apple platforms
|
|
15
|
+
* On other platforms, it continues to check the cast action state even when the app is in background
|
|
16
|
+
*/
|
|
17
|
+
export const useIsCasting = () => {
|
|
18
|
+
const actionContext = useActions(CHROMECAST_IDENTIFIER);
|
|
19
|
+
const appState = useAppState();
|
|
20
|
+
const isAppInForeground = appState === "active";
|
|
21
|
+
const shouldOnlyUpdateInForeground = isApplePlatform();
|
|
22
|
+
|
|
23
|
+
const [castActionState, setCastActionState] = React.useState(
|
|
24
|
+
!actionContext ? null : actionContext.initialEntryState(fakeEntry)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (!shouldOnlyUpdateInForeground || isAppInForeground) {
|
|
29
|
+
if (actionContext && castActionState === null) {
|
|
30
|
+
setCastActionState(actionContext.initialEntryState(fakeEntry));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [
|
|
34
|
+
actionContext,
|
|
35
|
+
setCastActionState,
|
|
36
|
+
isAppInForeground,
|
|
37
|
+
shouldOnlyUpdateInForeground,
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
if (typeof actionContext?.addListener === "function") {
|
|
42
|
+
return actionContext?.addListener(String(fakeEntry.id), (state) => {
|
|
43
|
+
// Only check foreground state on Apple platforms
|
|
44
|
+
if (!shouldOnlyUpdateInForeground || isAppInForeground) {
|
|
45
|
+
setCastActionState(state);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}, [
|
|
50
|
+
setCastActionState,
|
|
51
|
+
actionContext,
|
|
52
|
+
isAppInForeground,
|
|
53
|
+
shouldOnlyUpdateInForeground,
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
return !!castActionState?.connected;
|
|
57
|
+
};
|
|
@@ -5,9 +5,9 @@ import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
|
5
5
|
|
|
6
6
|
import { findComponentByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
|
|
7
7
|
import {
|
|
8
|
-
usePlugins,
|
|
9
|
-
useAppSelector,
|
|
10
8
|
selectComponents,
|
|
9
|
+
useAppSelector,
|
|
10
|
+
usePlugins,
|
|
11
11
|
} from "@applicaster/zapp-react-native-redux";
|
|
12
12
|
|
|
13
13
|
type Decorator = (component: React.Component<any>) => React.Component<any>;
|
|
@@ -130,6 +130,51 @@ describe("RefreshCoordinator", () => {
|
|
|
130
130
|
sub2.unsubscribe();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
// ----------------------------------------
|
|
134
|
+
// triggerRefresh
|
|
135
|
+
// ----------------------------------------
|
|
136
|
+
it("triggerRefresh emits refresh events for each component", () => {
|
|
137
|
+
const component1 = { id: "c1" } as ZappUIComponent;
|
|
138
|
+
const component2 = { id: "c2" } as ZappUIComponent;
|
|
139
|
+
const listener = jest.fn();
|
|
140
|
+
|
|
141
|
+
// Subscribe to all events
|
|
142
|
+
(refreshCoordinator as any).refresh$.subscribe(listener);
|
|
143
|
+
|
|
144
|
+
refreshCoordinator.triggerRefresh([component1, component2], screenId);
|
|
145
|
+
|
|
146
|
+
expect(listener).toHaveBeenCalledTimes(2);
|
|
147
|
+
|
|
148
|
+
expect(listener).toHaveBeenCalledWith({
|
|
149
|
+
component: component1,
|
|
150
|
+
screenId,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
expect(listener).toHaveBeenCalledWith({
|
|
154
|
+
component: component2,
|
|
155
|
+
screenId,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("triggerRefresh with empty components does nothing", () => {
|
|
160
|
+
const listener = jest.fn();
|
|
161
|
+
|
|
162
|
+
(refreshCoordinator as any).refresh$.subscribe(listener);
|
|
163
|
+
|
|
164
|
+
refreshCoordinator.triggerRefresh([], screenId);
|
|
165
|
+
|
|
166
|
+
expect(listener).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("triggerRefresh events are picked up by subscribeTo", () => {
|
|
170
|
+
const listener = jest.fn();
|
|
171
|
+
|
|
172
|
+
refreshCoordinator.subscribeTo(component, screenId, listener);
|
|
173
|
+
refreshCoordinator.triggerRefresh([component], screenId);
|
|
174
|
+
|
|
175
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
176
|
+
});
|
|
177
|
+
|
|
133
178
|
// ----------------------------------------
|
|
134
179
|
// clear
|
|
135
180
|
// ----------------------------------------
|
|
@@ -16,12 +16,26 @@ type ComponentToRefresh = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Public contract for refresh coordination.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* The coordinator serves as an event bus for component refresh events.
|
|
20
|
+
* It supports two types of producers and any number of consumers:
|
|
21
|
+
*
|
|
22
|
+
* Producers (push events into refresh$):
|
|
23
|
+
* register() → starts a periodic timer that emits refresh events
|
|
24
|
+
* triggerRefresh() → imperatively emits refresh events (e.g. pull-to-refresh)
|
|
25
|
+
*
|
|
26
|
+
* Consumers (react to refresh events):
|
|
27
|
+
* subscribeTo() → listen to refresh events for a specific component/screen
|
|
28
|
+
* subscribeToAny() → listen to all refresh events with throttling
|
|
29
|
+
*
|
|
30
|
+
* Note: subscribeTo() works independently of register(). A component can
|
|
31
|
+
* subscribe to refresh events without having auto-refresh enabled.
|
|
32
|
+
* This is how pull-to-refresh works — triggerRefresh() pushes events that
|
|
33
|
+
* are picked up by existing subscribeTo() listeners in UrlFeedResolver,
|
|
34
|
+
* even for components that don't have periodic auto-refresh timers.
|
|
22
35
|
*/
|
|
23
36
|
interface IRefreshCoordinator {
|
|
24
37
|
register(component: ZappUIComponent, screenId: string): () => void;
|
|
38
|
+
triggerRefresh(components: ZappUIComponent[], screenId: string): void;
|
|
25
39
|
subscribeTo(
|
|
26
40
|
component: ZappUIComponent,
|
|
27
41
|
screenId: string,
|
|
@@ -37,8 +51,10 @@ interface IRefreshCoordinator {
|
|
|
37
51
|
*
|
|
38
52
|
* Design goals:
|
|
39
53
|
* - One shared coordinator across the app
|
|
40
|
-
* -
|
|
41
|
-
* - Multiple
|
|
54
|
+
* - Central refresh$ event bus for all refresh events
|
|
55
|
+
* - Multiple producers: periodic timers (register) and imperative triggers (triggerRefresh)
|
|
56
|
+
* - Multiple consumers: per-component (subscribeTo) and global (subscribeToAny)
|
|
57
|
+
* - Producers and consumers are independent — subscribeTo works without register
|
|
42
58
|
* - Safe cleanup of timers and subscriptions
|
|
43
59
|
*/
|
|
44
60
|
class RefreshCoordinator implements IRefreshCoordinator {
|
|
@@ -114,6 +130,19 @@ class RefreshCoordinator implements IRefreshCoordinator {
|
|
|
114
130
|
return (): void => this.unregister(componentId, screenId);
|
|
115
131
|
}
|
|
116
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Imperatively triggers refresh for the given components on a screen.
|
|
135
|
+
*
|
|
136
|
+
* Pushes each component into the central refresh$ stream so that
|
|
137
|
+
* existing subscribers (e.g. UrlFeedResolver's reloadData) react
|
|
138
|
+
* to the event. Used by pull-to-refresh and programmatic refresh.
|
|
139
|
+
*/
|
|
140
|
+
public triggerRefresh(components: ZappUIComponent[], screenId: string): void {
|
|
141
|
+
components.forEach((component) => {
|
|
142
|
+
this.refresh$.next({ component, screenId });
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
117
146
|
/**
|
|
118
147
|
* Stops and removes timer for a specific component.
|
|
119
148
|
* Cleans up the RxJS subscription for that component's interval stream.
|