Skip to content

feature: menu group - default expand option #1389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/components/ui/menu/menuGroup.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { MenuItemDescriptor } from './menu.service';

export interface MenuGroupProps extends MenuItemProps {
children?: ChildrenWithProps<MenuItemProps>;
initiallyExpanded?: boolean;
}

export type MenuGroupElement = React.ReactElement<MenuGroupProps>;
Expand Down Expand Up @@ -59,6 +60,9 @@ const POSITION_OUTSCREEN: Point = Point.outscreen();
* to render to end of the *title*.
* Expected to return an Image.
*
* @property {boolean} initiallyExpanded - Boolean value which defines whether group should be initially expanded.
* If true - menu group will be expanded by default.
*
* @property {TouchableOpacityProps} ...TouchableOpacityProps - Any props applied to TouchableOpacity component.
*
* @overview-example MenuGroups
Expand All @@ -68,8 +72,23 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {
public state: State = {
submenuHeight: 1,
};

private initiallyExpanded: boolean;

private expandAnimation: Animated.Value = new Animated.Value(0);

constructor(props) {
super(props);
this.initiallyExpanded = props.initiallyExpanded;
}

public componentDidUpdate(prevProps: Readonly<MenuGroupProps>, prevState: Readonly<State>, snapshot?: any) {
const submenuHeightChanged = this.state.submenuHeight !== prevState.submenuHeight;
if (submenuHeightChanged && this.hasSubmenu && this.initiallyExpanded) {
this.expandAnimation.setValue(this.state.submenuHeight);
}
}

private get hasSubmenu(): boolean {
return React.Children.count(this.props.children) > 0;
}
Expand Down Expand Up @@ -102,6 +121,8 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {

private onPress = (descriptor: MenuItemDescriptor, event: GestureResponderEvent): void => {
if (this.hasSubmenu) {
this.initiallyExpanded = false;

const expandValue: number = this.expandAnimationValue > 0 ? 0 : this.state.submenuHeight;
this.createExpandAnimation(expandValue).start();
this.props.onPress && this.props.onPress(descriptor, event);
Expand Down Expand Up @@ -129,7 +150,7 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {

return (
<Animated.View style={{ transform: [{ rotate: this.expandToRotateInterpolation }] }}>
<ChevronDown {...evaProps} fill={style.tintColor}/>
<ChevronDown {...evaProps} fill={style.tintColor as string}/>
</Animated.View>
);
};
Expand All @@ -150,7 +171,7 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {

private renderMeasuringGroupedItems = (evaStyle): MeasuringElement => {
return (
<MeasureElement
<MeasureElement
shouldUseTopInsets={ModalService.getShouldUseTopInsets}
onMeasure={this.onSubmenuMeasure}>
{this.renderGroupedItems(evaStyle)}
Expand Down
2 changes: 1 addition & 1 deletion src/showcases/components/menu/menuGroups.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const MenuGroupsShowcase = () => {
<MenuItem title='UI Kitten' accessoryLeft={StarIcon}/>
<MenuItem title='Kitten Tricks' accessoryLeft={StarIcon}/>
</MenuGroup>
<MenuGroup title='Akveo Angular' accessoryLeft={BrowserIcon}>
<MenuGroup title='Akveo Angular' accessoryLeft={BrowserIcon} initiallyExpanded={true}>
<MenuItem title='Nebular' accessoryLeft={StarIcon}/>
<MenuItem title='ngx-admin' accessoryLeft={StarIcon}/>
<MenuItem title='UI Bakery' accessoryLeft={StarIcon}/>
Expand Down