Skip to content
Open
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
2 changes: 1 addition & 1 deletion apps/batiq-editor
3 changes: 2 additions & 1 deletion packages/components/src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Image as Image_ } from "native-base";
import { Image as ImageDefinition } from ".";

export const Image = (props: Static<typeof ImageDefinition.inputs>) => {
const { src, fallbackSrc, ...rest } = props;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { src, fallbackSrc, children, ...rest } = props;

return (
<Image_
Expand Down
110 changes: 107 additions & 3 deletions packages/expo-runtime/src/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from "react";
import { createBatiq, BaseBatiqCore, AppSchema } from "@batiq/core";
import React, { PropsWithChildren } from "react";
import { createBatiq, BaseBatiqCore, AppSchema, PageSchema } from "@batiq/core";
import { NavigationContainer, PathConfigMap } from "@react-navigation/native";
import { Runtime } from "./middlewares/runtimeMiddleware";
import { navigationRef } from "./Navigation";

const AppContext = React.createContext<BaseBatiqCore>(
// @ts-ignore
Expand All @@ -19,6 +22,7 @@ export const AppProvider = (
props: React.PropsWithChildren<{
schema: AppSchema;
middlewares?: Parameters<typeof createBatiq>[1];
importMaps?: Record<string, React.ComponentType>;
}>
) => {
const app = React.useMemo(
Expand All @@ -31,7 +35,107 @@ export const AppProvider = (
[props.schema, props.middlewares]
);
return (
<AppContext.Provider value={app}>{props.children}</AppContext.Provider>
<AppContext.Provider value={app}>
<AppNavigationContainer>{props.children}</AppNavigationContainer>
</AppContext.Provider>
);
};

type Page = {
name: string;
route: string;
};

type Tab = {
tab: NonNullable<PageSchema["navigation"]["tab"]>;
page: Page | Page[];
};

type Navigation = {
tabs: Record<string, Tab>;
stack: Page[];
};

export const toNavigation = (pages: PageSchema[]): Navigation =>
pages.reduce(
(navigation: Navigation, page: PageSchema): Navigation => {
if (!page.navigation.tab) {
return {
...navigation,
stack: [
...navigation.stack,
{ name: page.name, route: page.navigation.path },
],
};
}
const tab = navigation.tabs[page.navigation.tab.label];
return {
...navigation,
tabs: {
...navigation.tabs,
[page.navigation.tab.label]: tab
? {
...tab,
page: [
...(Array.isArray(tab.page) ? tab.page : [tab.page]),
{
name: page.name,
route: page.navigation.path,
},
],
}
: {
tab: page.navigation.tab,
page: {
name: page.name,
route: page.navigation.path,
},
},
},
};
},
{ tabs: {}, stack: [] }
);

const AppNavigationContainer: React.FC<PropsWithChildren> = ({ children }) => {
const batiq = useBatiq<BaseBatiqCore & Runtime>();
const schema = useBatiqSchema();
const { tabs, stack } = React.useMemo(() => {
return toNavigation(schema.pages);
}, [schema.pages]);

return (
<NavigationContainer
ref={navigationRef}
linking={{
prefixes: schema.config.link_prefixes ?? [],
config: {
screens: {
Tabs: {
screens: Object.fromEntries(
Object.entries(tabs).map(([label, tab]) => [
label,
Array.isArray(tab.page)
? ({
screens: Object.fromEntries(
tab.page.map((page) => [page.name, page.route])
),
} as const)
: tab.page.route,
])
),
},
...(Object.fromEntries(
stack.map((page) => [page.name, page.route])
) as PathConfigMap<{}>),
} as any,
},
}}
onStateChange={(state) => state && batiq.onNavigate(state)}
onReady={() => batiq.onNavigate(navigationRef.getRootState())}
>
{children}
</NavigationContainer>
);
};

Expand Down
70 changes: 17 additions & 53 deletions packages/expo-runtime/src/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import React from "react";
import { BaseBatiqCore, PageSchema } from "@batiq/core";
import {
createNavigationContainerRef,
NavigationContainer,
PathConfigMap,
} from "@react-navigation/native";
import { PageSchema } from "@batiq/core";
import { createNavigationContainerRef } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { useBatiq, useBatiqSchema } from "./AppContext";
import { Runtime } from "./middlewares/runtimeMiddleware";
import { useBatiqSchema } from "./AppContext";

type Page = {
component: React.ComponentType;
Expand Down Expand Up @@ -121,7 +116,6 @@ export const navigationRef = createNavigationContainerRef();
export const Navigation = (props: {
importMaps: Record<string, React.ComponentType>;
}) => {
const batiq = useBatiq<BaseBatiqCore & Runtime>();
const schema = useBatiqSchema();
const { tabs, stack } = React.useMemo(() => {
return toNavigation(schema.pages, props.importMaps);
Expand All @@ -131,51 +125,21 @@ export const Navigation = (props: {
const Tab = React.useCallback(() => createTabs(tabs), [tabs]);

return (
<NavigationContainer
ref={navigationRef}
linking={{
prefixes: schema.config.link_prefixes ?? [],
config: {
screens: {
Tabs: {
screens: Object.fromEntries(
Object.entries(tabs).map(([label, tab]) => [
label,
Array.isArray(tab.page)
? ({
screens: Object.fromEntries(
tab.page.map((page) => [page.name, page.route])
),
} as const)
: tab.page.route,
])
),
},
...(Object.fromEntries(
stack.map((page) => [page.name, page.route])
) as PathConfigMap<{}>),
} as any,
},
}}
onStateChange={(state) => state && batiq.onNavigate(state)}
onReady={() => batiq.onNavigate(navigationRef.getRootState())}
>
<Stack.Navigator>
<Stack.Navigator>
<Stack.Screen
name="Tabs"
component={Tab}
options={{
headerShown: false,
}}
/>
{stack.map((page) => (
<Stack.Screen
name="Tabs"
component={Tab}
options={{
headerShown: false,
}}
name={page.name}
component={page.component}
key={page.route}
/>
{stack.map((page) => (
<Stack.Screen
name={page.name}
component={page.component}
key={page.route}
/>
))}
</Stack.Navigator>
</NavigationContainer>
))}
</Stack.Navigator>
);
};
136 changes: 68 additions & 68 deletions packages/runtime/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,68 @@
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly are you pointing at ? if its link_prefixes its due to navigation when I tried to fix redirect issue, its not give any diff tho , i'll revert it back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I added some new compoundComponent just wanna try out @arrizalamin

"platform": "web",
"config": {
"link_prefixes": ["http://localhost:4400/", "app://"]
"link_prefixes": ["http://127.0.0.1:5174/", "app://"]
},
"datasource": {
"qore": {
"type": "qore",
"config": {
"endpoint": "https://batiq.qorebase.io"
"datasource": {},
"components": {
"ButtonGroup": {
"inputs": {},
"component": {
"type": "component",
"from": "@batiq/components",
"name": "Container",
"id": "ContainerButtonGroup",
"properties": {
"p": "4",
"direction": "horizontal",
"w": "full",
"gap": "2",
"bg": "white"
},
"children": [
{
"type": "component",
"from": "@batiq/components",
"name": "Button",
"id": "PrimaryButton",
"properties": {
"bg": "blue.500",
"flex": 1
},
"children": [
{
"type": "component",
"from": "@batiq/components",
"name": "Text",
"id": "PrimaryText",
"properties": {},
"children": ["Primary"]
}
]
},
{
"type": "component",
"from": "@batiq/components",
"name": "Button",
"id": "SecondaryButton",
"properties": {
"bg": "blue.100",
"flex": 1
},
"children": [
{
"type": "component",
"from": "@batiq/components",
"name": "Text",
"id": "PrimaryText",
"properties": {},
"children": ["Primary"]
}
]
}
]
}
},
"qore2": {
"type": {
"from": "@batiq/data",
"name": "CustomDataSource"
},
"config": {
"endpoint": "https://batiq.qorebase.io"
},
"authenticatedRoutes": ["/users", "/posts/*"]
},
"petstore": {
"type": {
"from": "@batiq/data",
"name": "OpenAPI"
},
"config": {
"definition": "https://petstore3.swagger.io/api/v3/openapi.json",
"auth": {
"apiKey": null
}
},
"authenticatedRoutes": ["/page-1"]
}
},
"components": {
"CompoundButton": {
"inputs": {},
"component": {
Expand Down Expand Up @@ -170,44 +198,13 @@
}
]
},
{
"type": "data",
"data": "petstore",
"name": "pet",
"query": {
"operationId": "getPetById",
"parameters": {
"petId": 1
}
},
"children": [
{
"type": "component",
"from": "@batiq/components",
"name": "Text",
"properties": {
"text": {
"type": "expression",
"expression": "pet.id"
}
},
"children": []
}
]
},
{
"type": "component",
"from": "@batiq/components",
"name": "Text",
"properties": {
"onPress": {
"type": "action",
"from": "@batiq/actions",
"name": "navigate",
"arguments": ["/page-2"]
}
},
"children": ["Page 2"]
"from": "local",
"name": "ButtonGroup",
"properties": {},
"overrideProperties": {},
"children": []
}
]
}
Expand All @@ -216,7 +213,10 @@
{
"name": "page 2",
"navigation": {
"path": "/page-2"
"path": "/page-2",
"tab": {
"label": "Element"
}
},
"children": [
{
Expand Down
Loading