@planningcenter/chat-react-native 4.5.0-rc.2 → 4.5.0-rc.3
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/build/components/display/filter_dropdown.d.ts.map +1 -1
- package/build/components/display/filter_dropdown.js +3 -1
- package/build/components/display/filter_dropdown.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/components/display/popover_menu_view.d.ts +8 -0
- package/build/components/display/popover_menu_view.d.ts.map +1 -0
- package/build/components/display/popover_menu_view.js +482 -0
- package/build/components/display/popover_menu_view.js.map +1 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +1 -2
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/design_system_screen.d.ts.map +1 -1
- package/build/screens/design_system_screen.js +289 -201
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/utils/native_adapters/menu.d.ts +1 -2
- package/build/utils/native_adapters/menu.d.ts.map +1 -1
- package/build/utils/native_adapters/menu.js +2 -41
- package/build/utils/native_adapters/menu.js.map +1 -1
- package/package.json +2 -2
- package/src/components/display/__tests__/filter_dropdown.test.tsx +18 -2
- package/src/components/display/__tests__/popover_menu_view.test.tsx +63 -0
- package/src/components/display/filter_dropdown.tsx +4 -2
- package/src/components/display/index.ts +1 -0
- package/src/components/display/popover_menu_view.tsx +239 -0
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +2 -12
- package/src/screens/conversations/conversations_screen.tsx +1 -2
- package/src/screens/design_system_screen.tsx +34 -1
- package/src/utils/native_adapters/menu.tsx +4 -18
- package/src/utils/native_adapters/__tests__/menu.test.tsx +0 -46
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/menu.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AASnD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,KAAK,CAAA;AAE1C,MAAM,WAAW,oBAAoB;IACnC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,UAAU,CAAC,EAAE,oBAAoB,CAAA;IACjC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IAChD,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,CAAA;AAMzD,qBAAa,WAAW;IACtB,IAAI,CAAC,EAAE,QAAQ,CAAA;gBAEH,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE;CAGzC"}
|
|
@@ -1,56 +1,17 @@
|
|
|
1
|
-
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
3
|
-
import { View } from 'react-native';
|
|
4
|
-
|
|
5
1
|
// =================================
|
|
6
2
|
// ====== Types ====================
|
|
7
3
|
// =================================
|
|
8
4
|
|
|
9
5
|
// Mirrors the props shared by `@expo/ui/community/menu` and
|
|
10
6
|
// `@react-native-menu/menu`, so a host can pass either `MenuView` straight in.
|
|
11
|
-
|
|
7
|
+
|
|
12
8
|
// =================================
|
|
13
9
|
// ====== Adapter ==================
|
|
14
10
|
// =================================
|
|
15
11
|
|
|
16
|
-
function UnconfiguredMenuView(t0) {
|
|
17
|
-
const $ = _c(5);
|
|
18
|
-
const {
|
|
19
|
-
children,
|
|
20
|
-
style,
|
|
21
|
-
testID
|
|
22
|
-
} = t0;
|
|
23
|
-
let t1;
|
|
24
|
-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
25
|
-
t1 = [];
|
|
26
|
-
$[0] = t1;
|
|
27
|
-
} else {
|
|
28
|
-
t1 = $[0];
|
|
29
|
-
}
|
|
30
|
-
useEffect(_temp, t1);
|
|
31
|
-
let t2;
|
|
32
|
-
if ($[1] !== children || $[2] !== style || $[3] !== testID) {
|
|
33
|
-
t2 = /*#__PURE__*/_jsx(View, {
|
|
34
|
-
style: style,
|
|
35
|
-
testID: testID,
|
|
36
|
-
children: children
|
|
37
|
-
});
|
|
38
|
-
$[1] = children;
|
|
39
|
-
$[2] = style;
|
|
40
|
-
$[3] = testID;
|
|
41
|
-
$[4] = t2;
|
|
42
|
-
} else {
|
|
43
|
-
t2 = $[4];
|
|
44
|
-
}
|
|
45
|
-
return t2;
|
|
46
|
-
}
|
|
47
|
-
function _temp() {
|
|
48
|
-
console.warn("ChatAdapters.configure() must include a menu adapter before rendering a menu");
|
|
49
|
-
}
|
|
50
12
|
export class MenuAdapter {
|
|
51
13
|
constructor(methods) {
|
|
52
|
-
this.View = methods?.View
|
|
53
|
-
this.isConfigured = !!methods?.View;
|
|
14
|
+
this.View = methods?.View;
|
|
54
15
|
}
|
|
55
16
|
}
|
|
56
17
|
//# sourceMappingURL=menu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","names":["
|
|
1
|
+
{"version":3,"file":"menu.js","names":["MenuAdapter","constructor","methods","View"],"sources":["../../../src/utils/native_adapters/menu.tsx"],"sourcesContent":["import React from 'react'\nimport { StyleProp, ViewStyle } from 'react-native'\n\n// =================================\n// ====== Types ====================\n// =================================\n\n// Mirrors the props shared by `@expo/ui/community/menu` and\n// `@react-native-menu/menu`, so a host can pass either `MenuView` straight in.\n\nexport type MenuActionState = 'on' | 'off'\n\nexport interface MenuActionAttributes {\n destructive?: boolean\n disabled?: boolean\n hidden?: boolean\n}\n\nexport interface MenuAction {\n id?: string\n title: string\n state?: MenuActionState\n attributes?: MenuActionAttributes\n subactions?: MenuAction[]\n displayInline?: boolean\n}\n\nexport interface MenuActionEvent {\n nativeEvent: { event: string }\n}\n\nexport interface MenuViewProps {\n actions: MenuAction[]\n onPressAction?: (event: MenuActionEvent) => void\n onOpenMenu?: () => void\n onCloseMenu?: () => void\n shouldOpenOnLongPress?: boolean\n title?: string\n style?: StyleProp<ViewStyle>\n testID?: string\n children?: React.ReactNode\n}\n\nexport type MenuView = React.ComponentType<MenuViewProps>\n\n// =================================\n// ====== Adapter ==================\n// =================================\n\nexport class MenuAdapter {\n View?: MenuView\n\n constructor(methods?: { View: MenuView }) {\n this.View = methods?.View\n }\n}\n"],"mappings":"AAGA;AACA;AACA;;AAEA;AACA;;AAqCA;AACA;AACA;;AAEA,OAAO,MAAMA,WAAW,CAAC;EAGvBC,WAAWA,CAACC,OAA4B,EAAE;IACxC,IAAI,CAACC,IAAI,GAAGD,OAAO,EAAEC,IAAI;EAC3B;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.5.0-rc.
|
|
3
|
+
"version": "4.5.0-rc.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "a6ed01aa8a0298b35f775b61fcd396f971dd69b1"
|
|
88
88
|
}
|
|
@@ -36,7 +36,7 @@ const FakeMenuView = ({ actions, onPressAction, children }: MenuViewProps) => {
|
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const configureAdapters = (menu?: MenuAdapter) => {
|
|
40
40
|
ChatAdapters.configure({
|
|
41
41
|
clipboard: new ClipboardAdapter({
|
|
42
42
|
getStringAsync: async () => '',
|
|
@@ -48,8 +48,12 @@ beforeAll(() => {
|
|
|
48
48
|
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
49
49
|
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
50
50
|
}),
|
|
51
|
-
menu
|
|
51
|
+
menu,
|
|
52
52
|
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
configureAdapters(new MenuAdapter({ View: FakeMenuView }))
|
|
53
57
|
})
|
|
54
58
|
|
|
55
59
|
const options = [
|
|
@@ -111,4 +115,16 @@ describe('FilterDropdown', () => {
|
|
|
111
115
|
expect(onMoreFilters).toHaveBeenCalledTimes(1)
|
|
112
116
|
expect(onSelect).not.toHaveBeenCalled()
|
|
113
117
|
})
|
|
118
|
+
|
|
119
|
+
it('opens the popover menu when the host configured no menu', () => {
|
|
120
|
+
configureAdapters()
|
|
121
|
+
const { onSelect } = renderFilterDropdown()
|
|
122
|
+
|
|
123
|
+
expect(screen.queryAllByRole('menuitem')).toHaveLength(0)
|
|
124
|
+
|
|
125
|
+
fireEvent.press(screen.getByRole('button', { name: 'Groups' }))
|
|
126
|
+
fireEvent.press(screen.getByRole('menuitem', { name: 'Teams' }))
|
|
127
|
+
|
|
128
|
+
expect(onSelect).toHaveBeenCalledWith('teams')
|
|
129
|
+
})
|
|
114
130
|
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { Text } from 'react-native'
|
|
4
|
+
import { MenuAction } from '../../../utils/native_adapters'
|
|
5
|
+
import { PopoverMenuView } from '../popover_menu_view'
|
|
6
|
+
|
|
7
|
+
const actions: MenuAction[] = [
|
|
8
|
+
{ id: 'all', title: 'All' },
|
|
9
|
+
{ id: 'groups', title: 'Groups', state: 'on' },
|
|
10
|
+
{ id: 'secret', title: 'Secret', attributes: { hidden: true } },
|
|
11
|
+
{
|
|
12
|
+
id: 'more',
|
|
13
|
+
title: '',
|
|
14
|
+
displayInline: true,
|
|
15
|
+
subactions: [{ id: 'more_filters', title: 'More filters' }],
|
|
16
|
+
},
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const renderMenu = () => {
|
|
20
|
+
const onPressAction = jest.fn()
|
|
21
|
+
|
|
22
|
+
render(
|
|
23
|
+
<PopoverMenuView actions={actions} onPressAction={onPressAction}>
|
|
24
|
+
<Text>Trigger</Text>
|
|
25
|
+
</PopoverMenuView>
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
fireEvent.press(screen.getByText('Trigger'))
|
|
29
|
+
|
|
30
|
+
return { onPressAction }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('PopoverMenuView', () => {
|
|
34
|
+
it('opens with a row per visible action, inline sections flattened, the on action checked', () => {
|
|
35
|
+
renderMenu()
|
|
36
|
+
|
|
37
|
+
expect(screen.getAllByRole('menuitem').map(item => item.props.accessibilityState)).toEqual([
|
|
38
|
+
{ selected: false, disabled: false },
|
|
39
|
+
{ selected: true, disabled: false },
|
|
40
|
+
{ selected: false, disabled: false },
|
|
41
|
+
])
|
|
42
|
+
expect(screen.getByRole('menuitem', { name: 'More filters' })).toBeTruthy()
|
|
43
|
+
expect(screen.queryByRole('menuitem', { name: 'Secret' })).toBeNull()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('reports the pressed action by id and closes', () => {
|
|
47
|
+
const { onPressAction } = renderMenu()
|
|
48
|
+
|
|
49
|
+
fireEvent.press(screen.getByRole('menuitem', { name: 'More filters' }))
|
|
50
|
+
|
|
51
|
+
expect(onPressAction).toHaveBeenCalledWith({ nativeEvent: { event: 'more_filters' } })
|
|
52
|
+
expect(screen.queryAllByRole('menuitem')).toHaveLength(0)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('closes without an action when the scrim is pressed', () => {
|
|
56
|
+
const { onPressAction } = renderMenu()
|
|
57
|
+
|
|
58
|
+
fireEvent.press(screen.getByLabelText('Close menu'))
|
|
59
|
+
|
|
60
|
+
expect(onPressAction).not.toHaveBeenCalled()
|
|
61
|
+
expect(screen.queryAllByRole('menuitem')).toHaveLength(0)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '../../utils'
|
|
11
11
|
import { tokens } from '../../vendor/tapestry/tokens'
|
|
12
12
|
import { Icon } from './icon'
|
|
13
|
+
import { PopoverMenuView } from './popover_menu_view'
|
|
13
14
|
import { Text } from './text'
|
|
14
15
|
|
|
15
16
|
// =================================
|
|
@@ -52,6 +53,7 @@ export function FilterDropdown({
|
|
|
52
53
|
maxWidth,
|
|
53
54
|
}: FilterDropdownProps) {
|
|
54
55
|
const styles = useStyles()
|
|
56
|
+
const MenuView = Menu.View ?? PopoverMenuView
|
|
55
57
|
|
|
56
58
|
const optionActions: MenuAction[] = options.map(option => ({
|
|
57
59
|
id: option.id,
|
|
@@ -75,7 +77,7 @@ export function FilterDropdown({
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
return (
|
|
78
|
-
<
|
|
80
|
+
<MenuView actions={actions} onPressAction={handlePressAction} style={styles.container}>
|
|
79
81
|
<View
|
|
80
82
|
style={[styles.trigger, maxWidth !== undefined && { maxWidth }]}
|
|
81
83
|
accessible
|
|
@@ -96,7 +98,7 @@ export function FilterDropdown({
|
|
|
96
98
|
accessibilityElementsHidden
|
|
97
99
|
/>
|
|
98
100
|
</View>
|
|
99
|
-
</
|
|
101
|
+
</MenuView>
|
|
100
102
|
)
|
|
101
103
|
}
|
|
102
104
|
|
|
@@ -25,6 +25,7 @@ export * from './text_inline_button'
|
|
|
25
25
|
export * from './text'
|
|
26
26
|
export * from './toggle_button'
|
|
27
27
|
export * from './filter_dropdown'
|
|
28
|
+
export * from './popover_menu_view'
|
|
28
29
|
export * from './keyboard_scroll_view'
|
|
29
30
|
export * from './keyboard_view'
|
|
30
31
|
export * from './platform_modal_header_buttons'
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { clamp } from 'lodash'
|
|
2
|
+
import React, { useRef, useState } from 'react'
|
|
3
|
+
import { Modal, Pressable, ScrollView, StyleSheet, useWindowDimensions, View } from 'react-native'
|
|
4
|
+
import { useChatContext } from '../../contexts/chat_context'
|
|
5
|
+
import { useCreateAndroidRippleColor, useFontScale, useTheme } from '../../hooks'
|
|
6
|
+
import { MenuAction, MenuViewProps, platformPressedOpacityStyle } from '../../utils'
|
|
7
|
+
import { tokens } from '../../vendor/tapestry/tokens'
|
|
8
|
+
import { Icon } from './icon'
|
|
9
|
+
import { Text } from './text'
|
|
10
|
+
|
|
11
|
+
// =================================
|
|
12
|
+
// ====== Constants ================
|
|
13
|
+
// =================================
|
|
14
|
+
|
|
15
|
+
const MENU_WIDTH = 240
|
|
16
|
+
const MENU_OFFSET = 4
|
|
17
|
+
const SCREEN_MARGIN = 16
|
|
18
|
+
|
|
19
|
+
const CLOSED_ANCHOR = { x: 0, y: 0, width: 0, height: 0 }
|
|
20
|
+
|
|
21
|
+
// =================================
|
|
22
|
+
// ====== Rows =====================
|
|
23
|
+
// =================================
|
|
24
|
+
|
|
25
|
+
type Row = { kind: 'action'; action: MenuAction } | { kind: 'separator' }
|
|
26
|
+
|
|
27
|
+
const actionId = (action: MenuAction) => action.id ?? action.title
|
|
28
|
+
|
|
29
|
+
const visibleActions = (actions: MenuAction[]) =>
|
|
30
|
+
actions.filter(action => !action.attributes?.hidden)
|
|
31
|
+
|
|
32
|
+
// Lays the actions out the way the native menus draw them: an inline section's
|
|
33
|
+
// subactions sit at the top level, divided from neighboring rows by a separator.
|
|
34
|
+
const buildRows = (actions: MenuAction[]): Row[] => {
|
|
35
|
+
const rows: Row[] = []
|
|
36
|
+
const pushSeparator = () => {
|
|
37
|
+
if (rows.length > 0 && rows[rows.length - 1].kind !== 'separator') {
|
|
38
|
+
rows.push({ kind: 'separator' })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
visibleActions(actions).forEach((action, index, visible) => {
|
|
43
|
+
if (action.displayInline && action.subactions) {
|
|
44
|
+
pushSeparator()
|
|
45
|
+
visibleActions(action.subactions).forEach(subaction =>
|
|
46
|
+
rows.push({ kind: 'action', action: subaction })
|
|
47
|
+
)
|
|
48
|
+
if (index < visible.length - 1) pushSeparator()
|
|
49
|
+
} else {
|
|
50
|
+
rows.push({ kind: 'action', action })
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return rows
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// =================================
|
|
58
|
+
// ====== Component ================
|
|
59
|
+
// =================================
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A JS-only `MenuView` for hosts that cannot supply a native menu. Wraps the
|
|
63
|
+
* trigger in a pressable and opens a popover of the actions under it, or above
|
|
64
|
+
* it when the trigger sits in the lower half of the window.
|
|
65
|
+
*/
|
|
66
|
+
export function PopoverMenuView({
|
|
67
|
+
actions,
|
|
68
|
+
onPressAction,
|
|
69
|
+
onOpenMenu,
|
|
70
|
+
onCloseMenu,
|
|
71
|
+
style,
|
|
72
|
+
testID,
|
|
73
|
+
children,
|
|
74
|
+
}: MenuViewProps) {
|
|
75
|
+
const triggerRef = useRef<View>(null)
|
|
76
|
+
const [expanded, setExpanded] = useState(false)
|
|
77
|
+
const [anchor, setAnchor] = useState(CLOSED_ANCHOR)
|
|
78
|
+
const { edgeToEdge = true } = useChatContext()
|
|
79
|
+
const { width: windowWidth, height: windowHeight } = useWindowDimensions()
|
|
80
|
+
const fontScale = useFontScale()
|
|
81
|
+
const styles = useStyles()
|
|
82
|
+
|
|
83
|
+
const open = () => {
|
|
84
|
+
triggerRef.current?.measureInWindow((x, y, width, height) => {
|
|
85
|
+
setAnchor({ x, y, width, height })
|
|
86
|
+
})
|
|
87
|
+
setExpanded(true)
|
|
88
|
+
onOpenMenu?.()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const close = () => {
|
|
92
|
+
setExpanded(false)
|
|
93
|
+
onCloseMenu?.()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const handlePress = (action: MenuAction) => {
|
|
97
|
+
onPressAction?.({ nativeEvent: { event: actionId(action) } })
|
|
98
|
+
close()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const menuWidth = clamp(MENU_WIDTH * fontScale, MENU_WIDTH, windowWidth - SCREEN_MARGIN * 2)
|
|
102
|
+
const anchorBottom = anchor.y + anchor.height
|
|
103
|
+
const opensUpward = anchor.y + anchor.height / 2 > windowHeight / 2
|
|
104
|
+
const menuPosition = {
|
|
105
|
+
width: menuWidth,
|
|
106
|
+
left: clamp(
|
|
107
|
+
anchor.x,
|
|
108
|
+
SCREEN_MARGIN,
|
|
109
|
+
Math.max(SCREEN_MARGIN, windowWidth - menuWidth - SCREEN_MARGIN)
|
|
110
|
+
),
|
|
111
|
+
...(opensUpward
|
|
112
|
+
? {
|
|
113
|
+
bottom: windowHeight - anchor.y + MENU_OFFSET,
|
|
114
|
+
maxHeight: anchor.y - MENU_OFFSET - SCREEN_MARGIN,
|
|
115
|
+
}
|
|
116
|
+
: {
|
|
117
|
+
top: anchorBottom + MENU_OFFSET,
|
|
118
|
+
maxHeight: windowHeight - anchorBottom - MENU_OFFSET - SCREEN_MARGIN,
|
|
119
|
+
}),
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<>
|
|
124
|
+
<Pressable ref={triggerRef} style={style} testID={testID} onPress={open} accessible={false}>
|
|
125
|
+
{children}
|
|
126
|
+
</Pressable>
|
|
127
|
+
<Modal
|
|
128
|
+
visible={expanded}
|
|
129
|
+
transparent
|
|
130
|
+
animationType="fade"
|
|
131
|
+
statusBarTranslucent={edgeToEdge}
|
|
132
|
+
navigationBarTranslucent={edgeToEdge}
|
|
133
|
+
onRequestClose={close}
|
|
134
|
+
>
|
|
135
|
+
<Pressable
|
|
136
|
+
style={styles.scrim}
|
|
137
|
+
onPress={close}
|
|
138
|
+
accessibilityRole="button"
|
|
139
|
+
accessibilityLabel="Close menu"
|
|
140
|
+
/>
|
|
141
|
+
<View style={[styles.menu, menuPosition]} accessibilityRole="menu">
|
|
142
|
+
<ScrollView bounces={false}>
|
|
143
|
+
{buildRows(actions).map((row, index) =>
|
|
144
|
+
row.kind === 'separator' ? (
|
|
145
|
+
<View key={index} style={styles.separator} />
|
|
146
|
+
) : (
|
|
147
|
+
<PopoverMenuItem
|
|
148
|
+
key={index}
|
|
149
|
+
action={row.action}
|
|
150
|
+
onPress={() => handlePress(row.action)}
|
|
151
|
+
/>
|
|
152
|
+
)
|
|
153
|
+
)}
|
|
154
|
+
</ScrollView>
|
|
155
|
+
</View>
|
|
156
|
+
</Modal>
|
|
157
|
+
</>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface PopoverMenuItemProps {
|
|
162
|
+
action: MenuAction
|
|
163
|
+
onPress: () => void
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function PopoverMenuItem({ action, onPress }: PopoverMenuItemProps) {
|
|
167
|
+
const styles = useStyles()
|
|
168
|
+
const { colors } = useTheme()
|
|
169
|
+
const androidRippleColor = useCreateAndroidRippleColor({ color: colors.fillColorNeutral050Base })
|
|
170
|
+
const selected = action.state === 'on'
|
|
171
|
+
const disabled = action.attributes?.disabled === true
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<Pressable
|
|
175
|
+
style={({ pressed }) => [
|
|
176
|
+
styles.item,
|
|
177
|
+
pressed && platformPressedOpacityStyle,
|
|
178
|
+
disabled && styles.itemDisabled,
|
|
179
|
+
]}
|
|
180
|
+
onPress={onPress}
|
|
181
|
+
disabled={disabled}
|
|
182
|
+
accessibilityRole="menuitem"
|
|
183
|
+
accessibilityState={{ selected, disabled }}
|
|
184
|
+
android_ripple={{ color: androidRippleColor, borderless: false, foreground: true }}
|
|
185
|
+
>
|
|
186
|
+
<Text style={styles.itemLabel}>{action.title}</Text>
|
|
187
|
+
{selected && (
|
|
188
|
+
<Icon name="general.check" style={styles.itemCheck} accessibilityElementsHidden />
|
|
189
|
+
)}
|
|
190
|
+
</Pressable>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// =================================
|
|
195
|
+
// ====== Styles ===================
|
|
196
|
+
// =================================
|
|
197
|
+
|
|
198
|
+
const useStyles = () => {
|
|
199
|
+
const { colors } = useTheme()
|
|
200
|
+
|
|
201
|
+
return StyleSheet.create({
|
|
202
|
+
scrim: {
|
|
203
|
+
...StyleSheet.absoluteFill,
|
|
204
|
+
},
|
|
205
|
+
menu: {
|
|
206
|
+
position: 'absolute',
|
|
207
|
+
paddingVertical: 4,
|
|
208
|
+
borderRadius: 8,
|
|
209
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
210
|
+
borderColor: colors.fillColorNeutral050Base,
|
|
211
|
+
backgroundColor: colors.fillColorNeutral100Inverted,
|
|
212
|
+
boxShadow: '0px 4px 12px rgba(0, 0, 0, 0.15)',
|
|
213
|
+
elevation: 4,
|
|
214
|
+
overflow: 'hidden',
|
|
215
|
+
},
|
|
216
|
+
item: {
|
|
217
|
+
flexDirection: 'row',
|
|
218
|
+
alignItems: 'center',
|
|
219
|
+
gap: 12,
|
|
220
|
+
paddingHorizontal: 16,
|
|
221
|
+
paddingVertical: 12,
|
|
222
|
+
},
|
|
223
|
+
itemDisabled: {
|
|
224
|
+
opacity: 0.4,
|
|
225
|
+
},
|
|
226
|
+
itemLabel: {
|
|
227
|
+
flex: 1,
|
|
228
|
+
},
|
|
229
|
+
itemCheck: {
|
|
230
|
+
fontSize: tokens.fontSizeSm,
|
|
231
|
+
color: colors.interaction,
|
|
232
|
+
},
|
|
233
|
+
separator: {
|
|
234
|
+
height: StyleSheet.hairlineWidth,
|
|
235
|
+
marginVertical: 4,
|
|
236
|
+
backgroundColor: colors.fillColorNeutral050Base,
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
ChatAdapters,
|
|
8
8
|
ClipboardAdapter,
|
|
9
9
|
ImagePickerAdapter,
|
|
10
|
-
MenuAdapter,
|
|
11
10
|
VideoAdapter,
|
|
12
11
|
} from '../../../utils/native_adapters'
|
|
13
12
|
import { ConversationsScreen } from '../conversations_screen'
|
|
@@ -41,7 +40,7 @@ jest.mock('../components/filter_dropdown_list_header_component', () => {
|
|
|
41
40
|
return { FilterDropdownListHeaderComponent: () => <Text>Filter dropdown header</Text> }
|
|
42
41
|
})
|
|
43
42
|
|
|
44
|
-
const configureAdapters = (
|
|
43
|
+
const configureAdapters = () => {
|
|
45
44
|
ChatAdapters.configure({
|
|
46
45
|
clipboard: new ClipboardAdapter({
|
|
47
46
|
getStringAsync: async () => '',
|
|
@@ -53,7 +52,6 @@ const configureAdapters = ({ menu }: { menu: boolean }) => {
|
|
|
53
52
|
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
54
53
|
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
55
54
|
}),
|
|
56
|
-
...(menu ? { menu: new MenuAdapter({ View: () => null }) } : {}),
|
|
57
55
|
})
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -80,7 +78,7 @@ const renderWithFeatures = (enabledFeatures: string[]) => {
|
|
|
80
78
|
|
|
81
79
|
describe('ConversationsScreen header gating', () => {
|
|
82
80
|
beforeEach(() => {
|
|
83
|
-
configureAdapters(
|
|
81
|
+
configureAdapters()
|
|
84
82
|
})
|
|
85
83
|
|
|
86
84
|
it('shows the search header with only the QA flag on', async () => {
|
|
@@ -107,14 +105,6 @@ describe('ConversationsScreen header gating', () => {
|
|
|
107
105
|
expect(await view.findByText('Filter dropdown header')).toBeTruthy()
|
|
108
106
|
})
|
|
109
107
|
|
|
110
|
-
it('falls back to the search header when the host has no menu adapter', async () => {
|
|
111
|
-
configureAdapters({ menu: false })
|
|
112
|
-
|
|
113
|
-
const view = renderWithFeatures(['QA_MOBILE_filter_dropdown', 'ROLLOUT_MOBILE_search'])
|
|
114
|
-
|
|
115
|
-
expect(await view.findByText('Search header')).toBeTruthy()
|
|
116
|
-
})
|
|
117
|
-
|
|
118
108
|
it('shows the default header with neither flag on', async () => {
|
|
119
109
|
const view = renderWithFeatures(['ROLLOUT_WEB_search'])
|
|
120
110
|
|
|
@@ -8,7 +8,6 @@ import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/us
|
|
|
8
8
|
import { useSearchEnabled } from '../../hooks/use_search_enabled'
|
|
9
9
|
import { AppName } from '../../types/resources/app_name'
|
|
10
10
|
import { GraphId } from '../../types/resources/group_resource'
|
|
11
|
-
import { Menu } from '../../utils/native_adapters'
|
|
12
11
|
import { FilterDropdownListHeaderComponent } from './components/filter_dropdown_list_header_component'
|
|
13
12
|
import { ListHeaderComponent } from './components/list_header_component'
|
|
14
13
|
import { SearchListHeaderComponent } from './components/search_list_header_component'
|
|
@@ -41,7 +40,7 @@ const useListHeaderComponent = () => {
|
|
|
41
40
|
const filterDropdownEnabled = useFilterDropdownEnabled()
|
|
42
41
|
const searchEnabled = useSearchEnabled()
|
|
43
42
|
|
|
44
|
-
if (filterDropdownEnabled
|
|
43
|
+
if (filterDropdownEnabled) return FilterDropdownListHeaderComponent
|
|
45
44
|
if (searchEnabled) return SearchListHeaderComponent
|
|
46
45
|
|
|
47
46
|
return ListHeaderComponent
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
IconButton,
|
|
21
21
|
Image,
|
|
22
22
|
Person,
|
|
23
|
+
PopoverMenuView,
|
|
23
24
|
Spinner,
|
|
24
25
|
Switch,
|
|
25
26
|
Text,
|
|
@@ -223,6 +224,7 @@ function PressablesSection({ isLast }: SectionProps) {
|
|
|
223
224
|
const styles = useStyles()
|
|
224
225
|
const [filterSelected, setFilterSelected] = useState('Groups')
|
|
225
226
|
const [dropdownSelected, setDropdownSelected] = useState('all')
|
|
227
|
+
const [popoverSelected, setPopoverSelected] = useState('all')
|
|
226
228
|
|
|
227
229
|
return (
|
|
228
230
|
<CollapsableSection title="Pressables" isLast={isLast}>
|
|
@@ -400,7 +402,7 @@ function PressablesSection({ isLast }: SectionProps) {
|
|
|
400
402
|
</Group>
|
|
401
403
|
<Group
|
|
402
404
|
title="FilterDropdown"
|
|
403
|
-
description="Trigger that opens the host's native menu of filter options plus a More filters action.
|
|
405
|
+
description="Trigger that opens the host's native menu of filter options plus a More filters action. Falls back to PopoverMenuView when the host configures no menu adapter."
|
|
404
406
|
>
|
|
405
407
|
<Row style={styles.alignRowLeft}>
|
|
406
408
|
<FilterDropdown
|
|
@@ -414,6 +416,37 @@ function PressablesSection({ isLast }: SectionProps) {
|
|
|
414
416
|
/>
|
|
415
417
|
</Row>
|
|
416
418
|
</Group>
|
|
419
|
+
<Group
|
|
420
|
+
title="PopoverMenuView"
|
|
421
|
+
description="The JS-only menu FilterDropdown falls back to when the host configures no menu adapter. Opens under the trigger, or above it when the trigger is in the lower half of the screen."
|
|
422
|
+
>
|
|
423
|
+
<Row style={styles.alignRowLeft}>
|
|
424
|
+
<PopoverMenuView
|
|
425
|
+
actions={[
|
|
426
|
+
...filterDropdownOptions.map(option => ({
|
|
427
|
+
id: option.id,
|
|
428
|
+
title: option.label,
|
|
429
|
+
state: option.id === popoverSelected ? ('on' as const) : ('off' as const),
|
|
430
|
+
})),
|
|
431
|
+
{
|
|
432
|
+
id: 'more',
|
|
433
|
+
title: '',
|
|
434
|
+
displayInline: true,
|
|
435
|
+
subactions: [{ id: 'more_filters', title: 'More filters' }],
|
|
436
|
+
},
|
|
437
|
+
]}
|
|
438
|
+
onPressAction={({ nativeEvent }) =>
|
|
439
|
+
nativeEvent.event === 'more_filters'
|
|
440
|
+
? Alert.alert('More filters')
|
|
441
|
+
: setPopoverSelected(nativeEvent.event)
|
|
442
|
+
}
|
|
443
|
+
>
|
|
444
|
+
<Text>
|
|
445
|
+
{filterDropdownOptions.find(option => option.id === popoverSelected)?.label} ▾
|
|
446
|
+
</Text>
|
|
447
|
+
</PopoverMenuView>
|
|
448
|
+
</Row>
|
|
449
|
+
</Group>
|
|
417
450
|
<Group
|
|
418
451
|
title="IconButton"
|
|
419
452
|
description="Supports different appearances, sizes, along with loading & disabled states. Use `iconStyle` for custom colors and font sizes. Requires `accessibilityLabel` as icon's don't provide context to screen readers."
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { StyleProp,
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native'
|
|
3
3
|
|
|
4
4
|
// =================================
|
|
5
5
|
// ====== Types ====================
|
|
@@ -47,24 +47,10 @@ export type MenuView = React.ComponentType<MenuViewProps>
|
|
|
47
47
|
// ====== Adapter ==================
|
|
48
48
|
// =================================
|
|
49
49
|
|
|
50
|
-
function UnconfiguredMenuView({ children, style, testID }: MenuViewProps) {
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
console.warn('ChatAdapters.configure() must include a menu adapter before rendering a menu')
|
|
53
|
-
}, [])
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<View style={style} testID={testID}>
|
|
57
|
-
{children}
|
|
58
|
-
</View>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
50
|
export class MenuAdapter {
|
|
63
|
-
View
|
|
64
|
-
isConfigured: boolean
|
|
51
|
+
View?: MenuView
|
|
65
52
|
|
|
66
53
|
constructor(methods?: { View: MenuView }) {
|
|
67
|
-
this.View = methods?.View
|
|
68
|
-
this.isConfigured = !!methods?.View
|
|
54
|
+
this.View = methods?.View
|
|
69
55
|
}
|
|
70
56
|
}
|