Skip to content
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

feature: menu group - default expand option #1389

Merged
merged 16 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 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>;
expanded?: boolean;
whitestranger7 marked this conversation as resolved.
Show resolved Hide resolved
}

export type MenuGroupElement = React.ReactElement<MenuGroupProps>;
Expand Down Expand Up @@ -58,6 +59,9 @@ const POSITION_OUTSCREEN: Point = Point.outscreen();
* @property {(ImageProps) => ReactElement} accessoryRight - Function component
* to render to end of the *title*.
* Expected to return an Image.
*
* @property {boolean} expanded - Boolean value to render expanded group by default.
* It true - menu group will be expanded by default.
*
* @property {TouchableOpacityProps} ...TouchableOpacityProps - Any props applied to TouchableOpacity component.
*
whitestranger7 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -110,12 +114,16 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {

private onSubmenuMeasure = (frame: Frame): void => {
this.setState({ submenuHeight: frame.size.height });
whitestranger7 marked this conversation as resolved.
Show resolved Hide resolved
if (this.props.expanded) {
const expandValue: number = this.expandAnimationValue > 0 ? 0 : this.state.submenuHeight;
this.createExpandAnimation(expandValue, 0).start();
}
};

private createExpandAnimation = (toValue: number): Animated.CompositeAnimation => {
private createExpandAnimation = (toValue: number, duration?: number): Animated.CompositeAnimation => {
return Animated.timing(this.expandAnimation, {
toValue: toValue,
duration: CHEVRON_ANIM_DURATION,
duration: duration || CHEVRON_ANIM_DURATION,
useNativeDriver: false,
});
};
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} expanded>
whitestranger7 marked this conversation as resolved.
Show resolved Hide resolved
<MenuItem title='Nebular' accessoryLeft={StarIcon}/>
<MenuItem title='ngx-admin' accessoryLeft={StarIcon}/>
<MenuItem title='UI Bakery' accessoryLeft={StarIcon}/>
Expand Down