|
@@ -13,35 +13,33 @@ import {
|
|
|
Easing,
|
|
Easing,
|
|
|
View
|
|
View
|
|
|
} from "react-native";
|
|
} from "react-native";
|
|
|
-import type {
|
|
|
|
|
- MenuButton,
|
|
|
|
|
- IMenuRef
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ type MenuButton as MenuButtonType
|
|
|
|
|
+} from "./components/menuButton/type";
|
|
|
|
|
+import {
|
|
|
|
|
+ type IMenuRef
|
|
|
} from "./type";
|
|
} from "./type";
|
|
|
import type IMenuProps from "./type";
|
|
import type IMenuProps from "./type";
|
|
|
import stylesheet, {
|
|
import stylesheet, {
|
|
|
useStyles
|
|
useStyles
|
|
|
} from "./stylesheet";
|
|
} from "./stylesheet";
|
|
|
|
|
+import MenuButton from "./components/menuButton";
|
|
|
import {
|
|
import {
|
|
|
|
|
+ NCoreUIKitMenu,
|
|
|
NCoreUIKitTheme
|
|
NCoreUIKitTheme
|
|
|
} from "../../core/hooks";
|
|
} from "../../core/hooks";
|
|
|
import type {
|
|
import type {
|
|
|
RefForwardingComponent
|
|
RefForwardingComponent
|
|
|
} from "../../types";
|
|
} from "../../types";
|
|
|
-import {
|
|
|
|
|
- ChevronRight as ChevronRightIcon,
|
|
|
|
|
- ChevronLeft as ChevronLeftIcon,
|
|
|
|
|
- ChevronDown as ChevronDownIcon
|
|
|
|
|
-} from "lucide-react-native";
|
|
|
|
|
import {
|
|
import {
|
|
|
SafeAreaView
|
|
SafeAreaView
|
|
|
} from "react-native-safe-area-context";
|
|
} from "react-native-safe-area-context";
|
|
|
import {
|
|
import {
|
|
|
Portal
|
|
Portal
|
|
|
} from "../../helpers/portalize";
|
|
} from "../../helpers/portalize";
|
|
|
|
|
+import Modal from "../modal";
|
|
|
import Seperator from "../seperator";
|
|
import Seperator from "../seperator";
|
|
|
import SiteLogo from "../siteLogo";
|
|
import SiteLogo from "../siteLogo";
|
|
|
-import RowCard from "../rowCard";
|
|
|
|
|
-import Modal from "../modal";
|
|
|
|
|
|
|
|
|
|
const Menu: RefForwardingComponent<IMenuRef, IMenuProps> = ({
|
|
const Menu: RefForwardingComponent<IMenuRef, IMenuProps> = ({
|
|
|
isWorkWithSafeAreaView = true,
|
|
isWorkWithSafeAreaView = true,
|
|
@@ -219,6 +217,53 @@ const Menu: RefForwardingComponent<IMenuRef, IMenuProps> = ({
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const updateMenuButtonCollabs = ({
|
|
|
|
|
+ depthMap,
|
|
|
|
|
+ status
|
|
|
|
|
+ }: {
|
|
|
|
|
+ depthMap: Array<number>;
|
|
|
|
|
+ status: boolean;
|
|
|
|
|
+ }) => {
|
|
|
|
|
+ const state = NCoreUIKitMenu.get({
|
|
|
|
|
+ id
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if(!state) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const recursivelyCatch = (item: Array<MenuButtonType>, index = 0): Array<MenuButtonType> => {
|
|
|
|
|
+ const tIndex = depthMap[index];
|
|
|
|
|
+
|
|
|
|
|
+ return item.map((c_item, c_index) => {
|
|
|
|
|
+ if(c_index !== tIndex) {
|
|
|
|
|
+ return c_item;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(index === depthMap.length - 1) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...c_item,
|
|
|
|
|
+ isCollabs: status
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...c_item,
|
|
|
|
|
+ subButtons: recursivelyCatch(c_item.subButtons as Array<MenuButtonType>, index + 1)
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const newButtons = recursivelyCatch(state.buttons);
|
|
|
|
|
+
|
|
|
|
|
+ state.buttons = newButtons;
|
|
|
|
|
+
|
|
|
|
|
+ NCoreUIKitMenu.update({
|
|
|
|
|
+ menuData: state,
|
|
|
|
|
+ id: id
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const renderHeader = () => {
|
|
const renderHeader = () => {
|
|
|
if(RenderHeader) {
|
|
if(RenderHeader) {
|
|
|
return <RenderHeader/>;
|
|
return <RenderHeader/>;
|
|
@@ -242,167 +287,21 @@ const Menu: RefForwardingComponent<IMenuRef, IMenuProps> = ({
|
|
|
</View>;
|
|
</View>;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const isPageActive = ((buttonItem: MenuButton) => {
|
|
|
|
|
- const state = navigation.getState();
|
|
|
|
|
- const currentRoute = state?.routes?.[state.index];
|
|
|
|
|
-
|
|
|
|
|
- if(!currentRoute) return false;
|
|
|
|
|
-
|
|
|
|
|
- if(currentRoute.state) {
|
|
|
|
|
- const nestedRoute = currentRoute.state.routes?.[currentRoute.state.index];
|
|
|
|
|
- return nestedRoute?.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
|
|
|
- } else if(currentRoute.name) {
|
|
|
|
|
- return currentRoute.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return currentRoute.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const renderMenuButton = (buttonItem: MenuButton, buttonIndex: number) => {
|
|
|
|
|
- const [
|
|
|
|
|
- isCollabs,
|
|
|
|
|
- setIsCollabs
|
|
|
|
|
- ] = useState(buttonItem.isCollabs);
|
|
|
|
|
-
|
|
|
|
|
- const [
|
|
|
|
|
- measure,
|
|
|
|
|
- setMeasure
|
|
|
|
|
- ] = useState<null | number>(null);
|
|
|
|
|
-
|
|
|
|
|
- const [
|
|
|
|
|
- ,
|
|
|
|
|
- setNavStateTracker
|
|
|
|
|
- ] = useState(Date.now());
|
|
|
|
|
-
|
|
|
|
|
- const animatedCollabs = useRef(new Animated.Value(0)).current;
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (!navigation || typeof navigation.addListener !== "function") return;
|
|
|
|
|
-
|
|
|
|
|
- const unsubscribeState = navigation.addListener("state", () => {
|
|
|
|
|
- setNavStateTracker(Date.now());
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const unsubscribeFocus = navigation.addListener("focus", () => {
|
|
|
|
|
- setNavStateTracker(Date.now());
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return () => {
|
|
|
|
|
- if (unsubscribeState) unsubscribeState();
|
|
|
|
|
- if (unsubscribeFocus) unsubscribeFocus();
|
|
|
|
|
- };
|
|
|
|
|
- }, [navigation]);
|
|
|
|
|
-
|
|
|
|
|
- if(buttonItem.isCollabsable) {
|
|
|
|
|
- useLayoutEffect(() => {
|
|
|
|
|
- if(measure === null) return;
|
|
|
|
|
-
|
|
|
|
|
- if(isCollabs) {
|
|
|
|
|
- Animated.timing(animatedCollabs, {
|
|
|
|
|
- useNativeDriver: Platform.OS !== "web",
|
|
|
|
|
- toValue: Number(measure),
|
|
|
|
|
- easing: Easing.linear,
|
|
|
|
|
- duration: 150
|
|
|
|
|
- }).start();
|
|
|
|
|
- } else {
|
|
|
|
|
- Animated.timing(animatedCollabs, {
|
|
|
|
|
- useNativeDriver: Platform.OS !== "web",
|
|
|
|
|
- easing: Easing.linear,
|
|
|
|
|
- duration: 150,
|
|
|
|
|
- toValue: 0
|
|
|
|
|
- }).start();
|
|
|
|
|
- }
|
|
|
|
|
- }, [isCollabs]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const isPActive = isPageActive(buttonItem);
|
|
|
|
|
-
|
|
|
|
|
- return <View
|
|
|
|
|
- key={`menu-button-${id}-${buttonIndex}`}
|
|
|
|
|
- >
|
|
|
|
|
- <RowCard
|
|
|
|
|
- {...buttonItem.props}
|
|
|
|
|
- rightIcon={
|
|
|
|
|
- buttonItem.isCollabsable || buttonItem.isShowRedirectIcon ?
|
|
|
|
|
- () => {
|
|
|
|
|
- if(buttonItem.isCollabsable) {
|
|
|
|
|
- if(isCollabs) {
|
|
|
|
|
- return <ChevronDownIcon
|
|
|
|
|
- color={isPActive ? colors.content.icon.onPrimary : colors.content.icon.low}
|
|
|
|
|
- size={18}
|
|
|
|
|
- />;
|
|
|
|
|
- } else {
|
|
|
|
|
- return <ChevronLeftIcon
|
|
|
|
|
- color={isPActive ? colors.content.icon.onPrimary : colors.content.icon.low}
|
|
|
|
|
- size={18}
|
|
|
|
|
- />;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- return <ChevronRightIcon
|
|
|
|
|
- color={isPActive ? colors.content.icon.onPrimary : colors.content.icon.low}
|
|
|
|
|
- size={18}
|
|
|
|
|
- />;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- :
|
|
|
|
|
- undefined
|
|
|
|
|
- }
|
|
|
|
|
- backgroundColor={isPActive ? "primary" : undefined}
|
|
|
|
|
- titleColor={isPActive ? "onPrimary" : undefined}
|
|
|
|
|
- iconColor={isPActive ? "onPrimary" : undefined}
|
|
|
|
|
- title={buttonItem.title}
|
|
|
|
|
- icon={buttonItem.icon}
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- if(buttonItem.isCollabsable) {
|
|
|
|
|
- setIsCollabs(!isCollabs);
|
|
|
|
|
- } else {
|
|
|
|
|
- if(buttonItem.redirectMain || buttonItem.redirectSub) {
|
|
|
|
|
- if(buttonItem.redirectMain && buttonItem.redirectSub) {
|
|
|
|
|
- navigation.navigate(buttonItem.redirectMain, {
|
|
|
|
|
- screen: buttonItem.redirectSub
|
|
|
|
|
- });
|
|
|
|
|
- } else if(buttonItem.redirectMain) {
|
|
|
|
|
- navigation.navigate(buttonItem.redirectMain);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(buttonItem.props?.onPress) buttonItem.props.onPress();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(closeAction && !buttonItem.isCollabsable) closeAction();
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- {
|
|
|
|
|
- buttonItem.subButtons && buttonItem.subButtons.length ?
|
|
|
|
|
- <Animated.View
|
|
|
|
|
- onLayout={buttonItem.isCollabsable ? (event) => {
|
|
|
|
|
- const height = event.nativeEvent.layout.height;
|
|
|
|
|
-
|
|
|
|
|
- if(height !== 0 && measure === null) setMeasure(height);
|
|
|
|
|
- } : undefined}
|
|
|
|
|
- style={[
|
|
|
|
|
- {
|
|
|
|
|
- height: measure === null ? "auto" : animatedCollabs
|
|
|
|
|
- }
|
|
|
|
|
- ]}
|
|
|
|
|
- >
|
|
|
|
|
- {buttonItem.subButtons.map((subButtonItem, subButtonIndex) => {
|
|
|
|
|
- return renderMenuButton(subButtonItem, subButtonIndex);
|
|
|
|
|
- })}
|
|
|
|
|
- </Animated.View>
|
|
|
|
|
- :
|
|
|
|
|
- null
|
|
|
|
|
- }
|
|
|
|
|
- </View>;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const renderButtons = () => {
|
|
const renderButtons = () => {
|
|
|
if(!buttons || !buttons.length) {
|
|
if(!buttons || !buttons.length) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return buttons.map((buttonItem, buttonIndex) => {
|
|
return buttons.map((buttonItem, buttonIndex) => {
|
|
|
- return renderMenuButton(buttonItem, buttonIndex);
|
|
|
|
|
|
|
+ return <MenuButton
|
|
|
|
|
+ updateMenuButtonCollabs={updateMenuButtonCollabs}
|
|
|
|
|
+ closeAction={closeAction}
|
|
|
|
|
+ buttonIndex={buttonIndex}
|
|
|
|
|
+ depthMap={[buttonIndex]}
|
|
|
|
|
+ buttonItem={buttonItem}
|
|
|
|
|
+ navigation={navigation}
|
|
|
|
|
+ id={id}
|
|
|
|
|
+ />;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|