Skip to content

Commit

Permalink
fix: add support for easy title + descriptions on web :)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLindhout committed Jun 24, 2023
1 parent bbcc08f commit bcc0cfb
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 54 deletions.
37 changes: 37 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

if [ -t 1 ] ; then
exec < /dev/tty ; # <- enables interactive shell
fi

dir="$(git rev-parse --show-toplevel)"

call_lefthook()
{
if lefthook -h >/dev/null 2>&1
then
eval lefthook $@
elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook"
then
eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook $@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook $@
elif npx @arkweid/lefthook -h >/dev/null 2>&1
then
npx @arkweid/lefthook $@
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook $@
else
echo "Can't find lefthook in PATH"
fi
}



call_lefthook "run commit-msg $@"
37 changes: 37 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

if [ -t 1 ] ; then
exec < /dev/tty ; # <- enables interactive shell
fi

dir="$(git rev-parse --show-toplevel)"

call_lefthook()
{
if lefthook -h >/dev/null 2>&1
then
eval lefthook $@
elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook"
then
eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook $@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook $@
elif npx @arkweid/lefthook -h >/dev/null 2>&1
then
npx @arkweid/lefthook $@
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook $@
else
echo "Can't find lefthook in PATH"
fi
}



call_lefthook "run pre-commit $@"
39 changes: 39 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

if [ -t 1 ] ; then
exec < /dev/tty ; # <- enables interactive shell
fi

dir="$(git rev-parse --show-toplevel)"

call_lefthook()
{
if lefthook -h >/dev/null 2>&1
then
eval lefthook $@
elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook"
then
eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook $@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook $@
elif npx @arkweid/lefthook -h >/dev/null 2>&1
then
npx @arkweid/lefthook $@
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook $@
else
echo "Can't find lefthook in PATH"
fi
}

# lefthook_version: 9df6c1f1f0b607d16db43f25a405e842

call_lefthook "install"

call_lefthook "run prepare-commit-msg $@"
4 changes: 3 additions & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"package": "com.webridge.navigation"
},
"web": {
"favicon": "./assets/favicon.png"
"favicon": "./assets/favicon.png",
"name": "Navigation",
"description": "Navigation"
},
"plugins": [
"./expo-plugin-android-material-you-bottom-bar",
Expand Down
26 changes: 23 additions & 3 deletions example/src/NavigatorScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ import {
export const AuthScreen = registerScreen(
'/auth',
lazy(() => import('./AuthScreen')),
() => {}
() => {},
{
title: 'Login',
description: 'Login to your account',
}
);
export const HomeScreen = registerScreen(
'/home',
lazy(() => import('./HomeScreen')),
() => {}
() => {},
{
title: 'Home',
description: 'Home is where the heart is',
}
);
export const AccountScreen = registerScreen(
'/account',
RequireAuthHOC(lazy(() => import('./AccountScreen'))),
() => {}
() => {},
{
title: 'Account',
description: 'Your account',
}
);

export const PostsScreen = registerScreen(
Expand All @@ -33,6 +45,10 @@ export const PostsScreen = registerScreen(
staleTime: 3000,
});
return 'testQueryReference';
},
{
title: 'Posts',
description: 'All posts',
}
);

Expand All @@ -47,5 +63,9 @@ export const PostScreen = registerScreen(
{ staleTime: 3000 }
);
return 'testQueryReference';
},
{
title: 'Post',
description: 'A post',
}
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/color": "^3.0.3",
"@types/jest": "^29.2.4",
"@types/react": "^18.0.28",
"@types/react-helmet": "^6.1.6",
"@types/react-native": "^0.71.3",
"color": "^4.2.3",
"commitlint": "^17.0.2",
Expand Down Expand Up @@ -177,6 +178,6 @@
},
"dependencies": {
"expo-status-bar": "^1.4.4",
"react-helmet-async": "^1.3.0"
"react-helmet": "^6.1.0"
}
}
2 changes: 1 addition & 1 deletion src/Head.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Helmet } from 'react-helmet-async';
import { Helmet } from 'react-helmet';

export function Head({ children }: { children: any }) {
return <Helmet>{children}</Helmet>;
Expand Down
21 changes: 18 additions & 3 deletions src/StatusBar.web.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import * as React from 'react';
import type { StatusBarProps } from 'expo-status-bar';

const getElement = () => document.querySelector('meta[name=theme-color]');
function StatusBar({ backgroundColor }: StatusBarProps) {
const originalColor = React.useRef<string | null>(
getElement()?.getAttribute('content') || null
);

React.useEffect(() => {
if (backgroundColor && typeof backgroundColor === 'string') {
const themeColor = document.querySelector('meta[name=theme-color]');
const themeColor = getElement();
themeColor?.setAttribute('content', backgroundColor);

const orgColor = originalColor.current;
return () => {
if (orgColor) {
themeColor?.setAttribute('content', orgColor);
} else {
themeColor?.remove();
}
};
}
return undefined;
}, [backgroundColor]);
return null;
}
export default StatusBar;
export default React.memo(StatusBar);
58 changes: 36 additions & 22 deletions src/navigation/NavigationStack.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,48 @@ import { NavigationMotion } from 'navigation-react-mobile';
import OptimizedContext, {
OptimizedContextProvider,
} from '../contexts/OptimizedContext';
import { Head } from '../Head';
import type { BaseScreen } from 'react-native-ridge-navigation';

function NavigationStack({ renderWeb }: { renderWeb?: (key: string) => any }) {
const { theme } = React.useContext(OptimizedContext);
return (
<NavigationMotion
duration={0}
renderMotion={(_, scene, key, ___, state, data) => (
<div
key={key}
style={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
overflow: 'hidden',
display: 'flex',
flex: 1,
flexDirection: 'column',
// opacity: 1,
backgroundColor: theme.layout.backgroundColor as any,
}}
>
<OptimizedContextProvider state={state} data={data}>
{renderWeb?.(state.key) || scene}
</OptimizedContextProvider>
</div>
)}
renderMotion={(_, scene, key, active, state, data) => {
const screen = state.screen as BaseScreen;
const screenOptions = screen?.options;
const title = screenOptions?.title;
const description = screenOptions?.description;
return (
<div
key={key}
style={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
overflow: 'hidden',
display: 'flex',
flex: 1,
flexDirection: 'column',
// opacity: 1,
backgroundColor: theme.layout.backgroundColor as any,
}}
>
{active && (
<Head>
<title>{title || ''}</title>
<meta name="description" content={description || ''} />
</Head>
)}
<OptimizedContextProvider state={state} data={data}>
{renderWeb?.(state.key) || scene}
</OptimizedContextProvider>
</div>
);
}}
/>
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/navigationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BaseScreen {
path: string;
element: ComponentType;
preload: (params: any) => any;
options?: ScreenOptions;
}

export interface FluentParams {
Expand Down Expand Up @@ -101,15 +102,20 @@ export function createNormalRoot(child: BaseScreen): RootChildNormal {
export type RootValue = RootChildNormal | RootChildBottomTabs;
export type Root = Record<string, RootValue>;

export type ScreenOptions = {
title?: string;
description?: string;
};
export function registerScreen<
Path extends string,
E extends ComponentType,
Preload extends (params: ExtractRouteParams<Path>) => void
>(path: Path, element: E, preload: Preload) {
>(path: Path, element: E, preload: Preload, options?: ScreenOptions) {
return {
path,
element,
preload,
options,
};
}

Expand Down
Loading

0 comments on commit bcc0cfb

Please sign in to comment.