@applicaster/zapp-react-native-ui-components 16.0.0-rc.71 → 16.0.0-rc.73
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/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +54 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +21 -0
- package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +58 -0
- package/Hooks/useEntryActionsExpander.ts +63 -0
- package/package.json +5 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useEntryActionState } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
3
|
+
import {
|
|
4
|
+
isActionAvailableFor,
|
|
5
|
+
RegisteredAction,
|
|
6
|
+
} from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
7
|
+
|
|
8
|
+
import { Button } from "../Button";
|
|
9
|
+
|
|
10
|
+
export type ActionButtonProps = {
|
|
11
|
+
entry: ZappEntry;
|
|
12
|
+
item: RegisteredAction;
|
|
13
|
+
configuration: any;
|
|
14
|
+
width: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Props = ActionButtonProps & {
|
|
18
|
+
onPress?: (item: any) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unified action button for the modal bottom sheet.
|
|
23
|
+
*
|
|
24
|
+
* Every item is a `RegisteredAction` resolved from the registry (entry actions,
|
|
25
|
+
* registry actions and legacy context-provider actions alike), so the button
|
|
26
|
+
* simply reads `item.action` and drives it through `useEntryActionState`
|
|
27
|
+
* (backed by the action's observable / `addListener`).
|
|
28
|
+
*/
|
|
29
|
+
export function ActionButton(props: Props) {
|
|
30
|
+
const { item, entry, onPress: onItemPress } = props;
|
|
31
|
+
|
|
32
|
+
const action = item?.action;
|
|
33
|
+
|
|
34
|
+
const { state, invokeAction } = useEntryActionState(action, entry);
|
|
35
|
+
|
|
36
|
+
const onPress = React.useCallback(
|
|
37
|
+
(_item) => {
|
|
38
|
+
invokeAction({
|
|
39
|
+
context: "toast",
|
|
40
|
+
dismiss: () => onItemPress?.(item),
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
[invokeAction, item, onItemPress]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!isActionAvailableFor(action, entry as ZappEntry)) return null;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Button {...props} item={state} onPress={onPress} label={state?.label} />
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Explicitly set display name for the component
|
|
54
|
+
ActionButton.displayName = "ActionButton";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { ActionButton, ActionButtonProps } from "./ActionButton";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Binds an entry to the sheet's row button.
|
|
7
|
+
*
|
|
8
|
+
* `BottomSheetModalContent` renders `buttonComponent` per item and does not
|
|
9
|
+
* know about entries, so the entry is closed over here instead.
|
|
10
|
+
*/
|
|
11
|
+
export const boundActionButton = (entry: ZappEntry | ZappFeed) => {
|
|
12
|
+
const ActionButtonWithEntry = (props: ActionButtonProps) => (
|
|
13
|
+
<ActionButton {...props} entry={entry as ZappEntry} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
ActionButtonWithEntry.displayName = "ActionButtonWithEntry";
|
|
17
|
+
|
|
18
|
+
return ActionButtonWithEntry;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
boundActionButton.displayName = "boundActionButton";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ActionButton } from "./ActionButton";
|
|
2
|
+
|
|
3
|
+
export type { ActionButtonProps } from "./ActionButton";
|
|
4
|
+
|
|
5
|
+
export { boundActionButton } from "./boundActionButton";
|
|
6
|
+
|
|
7
|
+
export { openActionsBottomSheet } from "./openActionsBottomSheet";
|
|
8
|
+
|
|
9
|
+
export type { OpenActionsBottomSheetArgs } from "./openActionsBottomSheet";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
|
+
import { openBottomSheetModal } from "@applicaster/zapp-react-native-utils/modalState";
|
|
3
|
+
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
4
|
+
import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
5
|
+
|
|
6
|
+
import { boundActionButton } from "./boundActionButton";
|
|
7
|
+
|
|
8
|
+
const { log_warning } = createLogger({
|
|
9
|
+
subsystem: "ActionsBottomSheet",
|
|
10
|
+
category: "Presentation",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type OpenActionsBottomSheetArgs = {
|
|
14
|
+
/** Entry the actions act on; bound into every row button. */
|
|
15
|
+
entry: ZappEntry | ZappFeed;
|
|
16
|
+
/** Already resolved and merged actions, in the order they should appear. */
|
|
17
|
+
actions: RegisteredAction[];
|
|
18
|
+
title?: string;
|
|
19
|
+
summary?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Presents a list of resolved actions in the shared bottom sheet.
|
|
24
|
+
*
|
|
25
|
+
* This is the core entry point for "show these actions in a sheet": the
|
|
26
|
+
* open-modal-bottom-sheet plugin uses it for its configured list, and the
|
|
27
|
+
* player overflow uses it for the actions that did not fit on the overlay.
|
|
28
|
+
* Neither has to know about the other, and neither needs the plugin installed.
|
|
29
|
+
*/
|
|
30
|
+
export function openActionsBottomSheet({
|
|
31
|
+
entry,
|
|
32
|
+
actions,
|
|
33
|
+
title,
|
|
34
|
+
summary,
|
|
35
|
+
}: OpenActionsBottomSheetArgs): void {
|
|
36
|
+
if (!actions?.length) {
|
|
37
|
+
// Every action resolved away - unavailable for this entry, or not
|
|
38
|
+
// invokable. An empty sheet looks broken, so say why and stay put.
|
|
39
|
+
log_warning(
|
|
40
|
+
"openActionsBottomSheet: nothing to present - not opening the sheet",
|
|
41
|
+
{ entryId: (entry as ZappEntry)?.id }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
openBottomSheetModal({
|
|
48
|
+
modalBottomSheetContentProps: {
|
|
49
|
+
// TODO: should be optional - the button handles its own tap, but
|
|
50
|
+
// BottomSheetModalContent still requires an onPress.
|
|
51
|
+
onPress: noop,
|
|
52
|
+
items: actions,
|
|
53
|
+
buttonComponent: boundActionButton(entry),
|
|
54
|
+
title,
|
|
55
|
+
summary,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
|
|
4
|
+
import {
|
|
5
|
+
buildEntryActions,
|
|
6
|
+
EntryActionDeps,
|
|
7
|
+
} from "@applicaster/zapp-react-native-utils/entryActions";
|
|
8
|
+
import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
9
|
+
import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore";
|
|
10
|
+
import {
|
|
11
|
+
useCurrentScreenData,
|
|
12
|
+
useScreenContext,
|
|
13
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks/screen";
|
|
14
|
+
import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Expands `entry.extensions.entry_action` into invokable actions, against the
|
|
18
|
+
* screen this hook is called from.
|
|
19
|
+
*
|
|
20
|
+
* Entry actions are data on the entry, not an installed capability, so there is
|
|
21
|
+
* nothing to look up by identifier: the surface showing the entry expands them.
|
|
22
|
+
* That also decides which screen they execute against — the one whose tree this
|
|
23
|
+
* hook runs in, rather than whichever screen happened to be current when a
|
|
24
|
+
* global provider was registered.
|
|
25
|
+
*
|
|
26
|
+
* Pass the result to `resolveActionIdentifiers` / `resolvePlayerActions` as
|
|
27
|
+
* `expandEntryActions`.
|
|
28
|
+
*/
|
|
29
|
+
export function useEntryActionsExpander(): (
|
|
30
|
+
entry: ZappEntry | ZappFeed
|
|
31
|
+
) => RegisteredAction[] {
|
|
32
|
+
const { pathname } = useRoute();
|
|
33
|
+
|
|
34
|
+
const screenContext = useScreenContext();
|
|
35
|
+
const screenData = useCurrentScreenData();
|
|
36
|
+
const screenState = screenContext?.options;
|
|
37
|
+
const screenStateStore = useScreenStateStore();
|
|
38
|
+
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
39
|
+
|
|
40
|
+
// Read through a ref so the returned expander keeps a stable identity: it
|
|
41
|
+
// feeds `useMemo` dependency lists on surfaces that re-resolve their actions
|
|
42
|
+
// on every registry change.
|
|
43
|
+
const depsRef = React.useRef<EntryActionDeps>();
|
|
44
|
+
|
|
45
|
+
depsRef.current = {
|
|
46
|
+
actionExecutor,
|
|
47
|
+
actionContext: {
|
|
48
|
+
screenData,
|
|
49
|
+
screenState,
|
|
50
|
+
screenRoute: pathname,
|
|
51
|
+
screenStateStore,
|
|
52
|
+
// From the screen context, the way `useCellClick` builds the same bag.
|
|
53
|
+
// The ZappPipes entry context is a route-keyed map, so reading `.data`
|
|
54
|
+
// off it was always undefined.
|
|
55
|
+
screenEntry: screenContext?.entry,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return React.useCallback(
|
|
60
|
+
(entry: ZappEntry | ZappFeed) => buildEntryActions(entry, depsRef.current),
|
|
61
|
+
[]
|
|
62
|
+
);
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.73",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "16.0.0-rc.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-rc.73",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.73",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-rc.73",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-rc.73",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"react-native-sortables": "1.7.1",
|