|
@@ -26,13 +26,23 @@ import {
|
|
|
import RowCard from "../../../rowCard";
|
|
import RowCard from "../../../rowCard";
|
|
|
|
|
|
|
|
const isPageActive = ((buttonItem: MenuButtonType, navigation: NCoreUIKit.Navigation) => {
|
|
const isPageActive = ((buttonItem: MenuButtonType, navigation: NCoreUIKit.Navigation) => {
|
|
|
|
|
+ if (!navigation || typeof navigation.getState !== "function") {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const state = navigation.getState();
|
|
const state = navigation.getState();
|
|
|
- const currentRoute = state?.routes?.[state.index];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (!state || !state.routes) return false;
|
|
|
|
|
+
|
|
|
|
|
+ const activeIndex = state.index ?? 0;
|
|
|
|
|
+ const currentRoute = state?.routes?.[activeIndex];
|
|
|
|
|
|
|
|
if(!currentRoute) return false;
|
|
if(!currentRoute) return false;
|
|
|
|
|
|
|
|
if(currentRoute.state) {
|
|
if(currentRoute.state) {
|
|
|
- const nestedRoute = currentRoute.state.routes?.[currentRoute.state.index];
|
|
|
|
|
|
|
+ const nestedIndex = currentRoute.state.index ?? 0;
|
|
|
|
|
+ const nestedRoute = currentRoute.state.routes?.[nestedIndex];
|
|
|
|
|
+
|
|
|
return nestedRoute?.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
return nestedRoute?.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
|
} else if(currentRoute.name) {
|
|
} else if(currentRoute.name) {
|
|
|
return currentRoute.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
return currentRoute.name === (buttonItem.redirectSub ?? buttonItem.redirectMain);
|
|
@@ -60,10 +70,15 @@ const MenuButton: FC<IMenuButton> = ({
|
|
|
] = useState<null | number>(null);
|
|
] = useState<null | number>(null);
|
|
|
|
|
|
|
|
const [
|
|
const [
|
|
|
- ,
|
|
|
|
|
|
|
+ navStateTracker,
|
|
|
setNavStateTracker
|
|
setNavStateTracker
|
|
|
] = useState(Date.now());
|
|
] = useState(Date.now());
|
|
|
|
|
|
|
|
|
|
+ const [
|
|
|
|
|
+ isShowSubs,
|
|
|
|
|
+ setIsShowSubs
|
|
|
|
|
+ ] = useState(buttonItem.isCollapse);
|
|
|
|
|
+
|
|
|
const animatedCollabs = useRef(new Animated.Value(0)).current;
|
|
const animatedCollabs = useRef(new Animated.Value(0)).current;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -83,35 +98,47 @@ const MenuButton: FC<IMenuButton> = ({
|
|
|
};
|
|
};
|
|
|
}, [navigation]);
|
|
}, [navigation]);
|
|
|
|
|
|
|
|
- if(buttonItem.isCollapsible) {
|
|
|
|
|
- useLayoutEffect(() => {
|
|
|
|
|
- if(measure === null) return;
|
|
|
|
|
-
|
|
|
|
|
- if(buttonItem.isCollapse) {
|
|
|
|
|
- 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();
|
|
|
|
|
- }
|
|
|
|
|
- }, [
|
|
|
|
|
- buttonItem.isCollapse,
|
|
|
|
|
- measure
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ useLayoutEffect(() => {
|
|
|
|
|
+ if(isShowSubs) {
|
|
|
|
|
+ Animated.timing(animatedCollabs, {
|
|
|
|
|
+ toValue: Platform.OS === "web" ? Number(measure) : 1,
|
|
|
|
|
+ useNativeDriver: Platform.OS !== "web",
|
|
|
|
|
+ easing: Easing.linear,
|
|
|
|
|
+ duration: 150
|
|
|
|
|
+ }).start();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [isShowSubs]);
|
|
|
|
|
+
|
|
|
|
|
+ useLayoutEffect(() => {
|
|
|
|
|
+ if(!buttonItem.isCollapsible) return;
|
|
|
|
|
+
|
|
|
|
|
+ if(Platform.OS === "web" && measure === null) return;
|
|
|
|
|
+
|
|
|
|
|
+ if(buttonItem.isCollapse) {
|
|
|
|
|
+ setIsShowSubs(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Animated.timing(animatedCollabs, {
|
|
|
|
|
+ useNativeDriver: Platform.OS !== "web",
|
|
|
|
|
+ easing: Easing.linear,
|
|
|
|
|
+ duration: 150,
|
|
|
|
|
+ toValue: 0
|
|
|
|
|
+ }).start(({
|
|
|
|
|
+ finished
|
|
|
|
|
+ }) => {
|
|
|
|
|
+ if(finished) {
|
|
|
|
|
+ setIsShowSubs(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [
|
|
|
|
|
+ buttonItem.isCollapse,
|
|
|
|
|
+ measure
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
const isPActive = isPageActive(buttonItem, navigation);
|
|
const isPActive = isPageActive(buttonItem, navigation);
|
|
|
|
|
|
|
|
return <View
|
|
return <View
|
|
|
- key={`menu-button-${id}-${buttonIndex}`}
|
|
|
|
|
|
|
+ key={`menu-button-${id}-${buttonIndex}-${navStateTracker.toString()}`}
|
|
|
>
|
|
>
|
|
|
<RowCard
|
|
<RowCard
|
|
|
{...buttonItem.props}
|
|
{...buttonItem.props}
|
|
@@ -178,9 +205,16 @@ const MenuButton: FC<IMenuButton> = ({
|
|
|
if(height !== 0 && measure === null) setMeasure(height);
|
|
if(height !== 0 && measure === null) setMeasure(height);
|
|
|
} : undefined}
|
|
} : undefined}
|
|
|
style={[
|
|
style={[
|
|
|
- {
|
|
|
|
|
|
|
+ Platform.OS === "web" ? {
|
|
|
height: measure === null ? "auto" : animatedCollabs,
|
|
height: measure === null ? "auto" : animatedCollabs,
|
|
|
overflow: "hidden"
|
|
overflow: "hidden"
|
|
|
|
|
+ } : {
|
|
|
|
|
+ display: isShowSubs ? "flex" : "none",
|
|
|
|
|
+ transform: [{
|
|
|
|
|
+ scaleY: animatedCollabs
|
|
|
|
|
+ }],
|
|
|
|
|
+ transformOrigin: "top",
|
|
|
|
|
+ overflow: "hidden"
|
|
|
}
|
|
}
|
|
|
]}
|
|
]}
|
|
|
>
|
|
>
|