Skip to content

Commit

Permalink
fix: demo app can't dislay in doc site (#693)
Browse files Browse the repository at this point in the history
* ci: add new CI job for testing

* chore: remove unused linting before commit

* ci: update testing CI

* ci: update yarn caching logic

* ci: refacor dependency caching logic in ci files

* ci: update CI trigger time

* docs: update example baseUrl

* fix: demo app can't dislay in doc site
  • Loading branch information
dohooo authored Oct 5, 2024
1 parent 4f24b18 commit 2faaa71
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
16 changes: 7 additions & 9 deletions example/app/app/+html.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ScrollViewStyleReset } from "expo-router/html";
import { WebProvider } from "@/store/WebProvider";
import { MAX_WIDTH } from "@/constants/sizes";

// This file is web-only and used to configure the root HTML for every
// web page during static rendering.
Expand All @@ -17,6 +16,12 @@ export default function Root({ children }: { children: React.ReactNode }) {
content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1"
/>

{/* This CSP used to control which domain could embed this App. For now, we're using this App in doc site. */}
<meta
httpEquiv="Content-Security-Policy"
content="frame-ancestors 'self' https://app.rn-carousel.dev http://localhost:8002"
/>

{/*
Disable body scrolling on web. This makes ScrollView components work closer to how they do on native.
However, body scrolling is often nice to have for mobile web. If you want to enable it, remove this line.
Expand All @@ -26,7 +31,7 @@ export default function Root({ children }: { children: React.ReactNode }) {
{/* Using raw CSS styles as an escape-hatch to ensure the background color never flickers in dark-mode. */}
<style
dangerouslySetInnerHTML={{
__html: viewportStyles,
__html: ``,
}}
/>

Expand All @@ -38,10 +43,3 @@ export default function Root({ children }: { children: React.ReactNode }) {
</html>
);
}

const viewportStyles = `
html, body {
max-width: ${MAX_WIDTH}px;
margin: 0 auto;
}
`;
109 changes: 59 additions & 50 deletions example/app/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { I18nManager, View } from "react-native";
import { I18nManager, Text, View } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { TamaguiProvider } from "tamagui";
import { TamaguiProvider, XStack, YStack } from "tamagui";
import { tamaguiConfig } from "../tamagui.config";

import FontAwesome from "@expo/vector-icons/FontAwesome";
Expand All @@ -14,14 +14,9 @@ import { useWebContext } from "@/store/WebProvider";
import { CaptureProvider } from "@/store/CaptureProvider";
import { HeaderRight } from "@/components/HeaderRight";
import { routes } from "./routes";
import {
useGlobalSearchParams,
useLocalSearchParams,
useNavigation,
usePathname,
} from "expo-router";
import { useInDoc } from "@/hooks/useInDoc";
import { IS_WEB } from "@/constants/platform";
import { MAX_WIDTH } from "@/constants/sizes";

export {
// Catch any errors thrown by the Layout component.
Expand Down Expand Up @@ -79,53 +74,67 @@ function RootLayoutNav() {
}
}, [inDoc]);

const backgroundColor = inDoc
? tamaguiConfig.themes.dark.background.val
: tamaguiConfig.themes.light.background.val;

return (
<TamaguiProvider
config={tamaguiConfig}
defaultTheme={inDoc ? "dark" : "light"}
>
<View style={{ flex: 1 }}>
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider value={DefaultTheme}>
<CaptureProvider>
<Stack
initialRouteName="/"
screenOptions={{
headerShown: !inDoc && webHeaderShown,
contentStyle: {
flex: 1,
backgroundColor: inDoc
? tamaguiConfig.themes.dark.background.val
: tamaguiConfig.themes.light.background.val,
},
headerRight: ({ tintColor }) => (
<HeaderRight
tintColor={tintColor}
isRTL={isRTL}
setIsRTL={setIsRTL}
/>
),
}}
>
<Stack.Screen name="index" />
{routes
.flatMap((item) =>
item.demos.map((demo) => ({ ...demo, kind: item.kind })),
)
.map((item) => (
<Stack.Screen
key={item.name}
name={`demos/${item.kind}/${item.name}/index`}
options={{
title: item.title,
}}
/>
))}
</Stack>
</CaptureProvider>
</ThemeProvider>
</GestureHandlerRootView>
</View>
<Providers>
<XStack
flex={1}
justifyContent="center"
backgroundColor={backgroundColor}
>
<YStack minWidth={IS_WEB ? MAX_WIDTH : "100%"} height={"100%"}>
<Stack
initialRouteName="/"
screenOptions={{
headerShown: !inDoc && webHeaderShown,
contentStyle: {
flex: 1,
backgroundColor,
},
headerRight: ({ tintColor }) => (
<HeaderRight
tintColor={tintColor}
isRTL={isRTL}
setIsRTL={setIsRTL}
/>
),
}}
>
<Stack.Screen name="index" />
{routes
.flatMap((item) =>
item.demos.map((demo) => ({ ...demo, kind: item.kind })),
)
.map((item) => (
<Stack.Screen
key={item.name}
name={`demos/${item.kind}/${item.name}/index`}
options={{
title: item.title,
}}
/>
))}
</Stack>
</YStack>
</XStack>
</Providers>
</TamaguiProvider>
);
}

const Providers = ({ children }: { children: React.ReactNode }) => {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider value={DefaultTheme}>
<CaptureProvider>{children}</CaptureProvider>
</ThemeProvider>
</GestureHandlerRootView>
);
};
2 changes: 1 addition & 1 deletion example/app/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StyleSheet } from "react-native";
import { ScrollView, TouchableOpacity } from "react-native-gesture-handler";

import { useNavigation, usePathname, useRouter } from "expo-router";
import { useRouter } from "expo-router";

import { useColor } from "@/hooks/useColor";
import { routes } from "./routes";
Expand Down
2 changes: 0 additions & 2 deletions example/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"name": "reanimated-carousel-website",
"version": "0.0.1",
"description": "Nextra docs template",
"author": "Shu Ding <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/dohooo/react-native-reanimated-carousel#readme",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2faaa71

Please sign in to comment.