ソースを参照

Bugfix: Wrapper problems fixed for Embedded Menu component.

lfabl 1 ヶ月 前
コミット
4f4dbe2b89

+ 4 - 13
example/src/navigation/index.tsx

@@ -1,11 +1,7 @@
 import {
     useEffect
 } from "react";
-import {
-    View
-} from "react-native";
 import type RootStackParamList from "./type";
-import stylesheet from "./stylesheet";
 import {
     NCoreUIKitEmbeddedMenu,
     NCoreUIKitTheme
@@ -96,15 +92,10 @@ const RootNav = () => {
         });
     }, []);
 
-    return <View
-        style={[
-            stylesheet.container
-        ]}
+    return <NCoreUIKitEmbeddedMenu.Render
+        navigation={navigation as unknown as NCoreUIKit.Navigation}
+        id="main-menu"
     >
-        <NCoreUIKitEmbeddedMenu.Render
-            navigation={navigation as unknown as NCoreUIKit.Navigation}
-            id="main-menu"
-        />
         <RootStack.Navigator
             initialRouteName="Home"
             screenOptions={{
@@ -120,7 +111,7 @@ const RootNav = () => {
                 component={ComponentsNav}
             />
         </RootStack.Navigator>
-    </View>;
+    </NCoreUIKitEmbeddedMenu.Render>;
 };
 
 const Navigation = () => {

+ 0 - 11
example/src/navigation/stylesheet.ts

@@ -1,11 +0,0 @@
-import {
-    StyleSheet
-} from "react-native";
-
-const stylesheet = StyleSheet.create({
-    container: {
-        flexDirection: "row",
-        flex: 1
-    }
-});
-export default stylesheet;

+ 1 - 1
src/components/embeddedMenu/components/menuButton/index.tsx

@@ -228,7 +228,7 @@ const EmbeddedMenuButton: FC<IEmbeddedMenuButton> = ({
                     if(buttonItem.props?.onPress) buttonItem.props.onPress();
                 }
 
-                if(closeAction) closeAction();
+                if(closeAction && !buttonItem.isCollapsible) closeAction();
             }}
         />
         {

+ 57 - 33
src/context/embeddedMenu.tsx

@@ -1,7 +1,9 @@
 import {
-    type ReactNode,
-    Fragment
+    type ReactNode
 } from "react";
+import {
+    View
+} from "react-native";
 import {
     type EmbeddedMenuContextType,
     type EmbeddedMenuDataType
@@ -9,10 +11,10 @@ import {
 import NCoreContext, {
     type ConfigType
 } from "ncore-context";
+import EmbeddedMenu from "../components/embeddedMenu";
 import {
     uuid
 } from "../utils";
-import EmbeddedMenu from "../components/embeddedMenu";
 
 class NCoreUIKitEmbeddedMenu extends NCoreContext<EmbeddedMenuContextType, ConfigType<EmbeddedMenuContextType>> {
     constructor({
@@ -212,6 +214,41 @@ class NCoreUIKitEmbeddedMenu extends NCoreContext<EmbeddedMenuContextType, Confi
             data
         } = this.useContext();
 
+        const renderMenu = ({
+            currentMenu
+        }: {
+            currentMenu: EmbeddedMenuDataType;
+        }) => {
+            return <EmbeddedMenu
+                {...currentMenu}
+                key={`NCoreUIKit-Menu-${currentMenu.id}`}
+                id={currentMenu.id as string}
+                close={() => {
+                    if(currentMenu.isAutoClosed) {
+                        this.close({
+                            id: currentMenu.id,
+                            index: index
+                        });
+                    }
+                }}
+                onClosed={() => {
+                    if(currentMenu.onClosed) {
+                        currentMenu.onClosed({
+                            id: currentMenu.id
+                        });
+                    }
+
+                    if(currentMenu.isAutoClosedOnClosed === undefined || currentMenu.isAutoClosedOnClosed === true) {
+                        this.close({
+                            id: currentMenu.id,
+                            index: index
+                        });
+                    }
+                }}
+                navigation={navigation}
+            />;
+        };
+
         if(id || index) {
             const currentMenu = data.find((dItem, dIndex) => {
                 if(id) {
@@ -225,38 +262,25 @@ class NCoreUIKitEmbeddedMenu extends NCoreContext<EmbeddedMenuContextType, Confi
                 return null;
             }
 
-            return <Fragment>
-                <EmbeddedMenu
-                    {...currentMenu}
-                    key={`NCoreUIKit-Menu-${currentMenu.id}`}
-                    id={currentMenu.id as string}
-                    close={() => {
-                        if(currentMenu.isAutoClosed) {
-                            this.close({
-                                id: currentMenu.id,
-                                index: index
-                            });
-                        }
-                    }}
-                    onClosed={() => {
-                        if(currentMenu.onClosed) {
-                            currentMenu.onClosed({
-                                id: currentMenu.id
-                            });
+            if(children) {
+                return <View
+                    style={[
+                        {
+                            flexDirection: "row",
+                            flex: 1
                         }
+                    ]}
+                >
+                    {renderMenu({
+                        currentMenu
+                    })}
+                    {children}
+                </View>;
+            }
 
-                        if(currentMenu.isAutoClosedOnClosed === undefined || currentMenu.isAutoClosedOnClosed === true) {
-                            console.log("yok bana geldi dayı ?");
-                            this.close({
-                                id: currentMenu.id,
-                                index: index
-                            });
-                        }
-                    }}
-                    navigation={navigation}
-                />
-                {children}
-            </Fragment>;
+            return renderMenu({
+                currentMenu
+            });
         }
 
         return null;