Skip to content

Commit

Permalink
[expo] fix screen header style
Browse files Browse the repository at this point in the history
**Summary**

apply colors from rneui theme.

**Test**

- expo

**Issue**

- N/A
  • Loading branch information
yssk22 committed Oct 20, 2023
1 parent 6eb2291 commit b23c877
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
3 changes: 2 additions & 1 deletion expo/features/root/TestRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AnalyticsProvider } from "@hpapp/contexts/analytics";
import { RelayProvider } from "@hpapp/contexts/relay";
import { SettingsProvider } from "@hpapp/contexts/settings";
import { LocalUserConfigurationSettings } from "@hpapp/contexts/settings/useLocalUserConfig";
import { CurrentUserSettings } from "@hpapp/features/auth";

const settings = [CurrentUserSettings];
const settings = [CurrentUserSettings, LocalUserConfigurationSettings];

export default function TestRoot({
children,
Expand Down
16 changes: 10 additions & 6 deletions expo/features/root/protected/stack/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { View, Text, Button } from "react-native";
import { createStackNavigator, useNavigation, defineScreen } from "./index";
import { screen, render, fireEvent } from "@testing-library/react-native";
import { AppThemeProvider } from "@hpapp/contexts/settings/theme";
import TestRoot from "@hpapp/features/root/TestRoot";

test("stack", async () => {
function Root({ children }: { children: React.ReactElement }) {
Expand Down Expand Up @@ -57,12 +59,14 @@ test("stack", async () => {

function StackContainer() {
return (
<>
<Stack
screens={[HomeScreen, ScreenWithParams, ScreenWithoutParams]}
initialRouteName="/"
/>
</>
<TestRoot>
<AppThemeProvider>
<Stack
screens={[HomeScreen, ScreenWithParams, ScreenWithoutParams]}
initialRouteName="/"
/>
</AppThemeProvider>
</TestRoot>
);
}

Expand Down
23 changes: 18 additions & 5 deletions expo/features/root/protected/stack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ function createStackNavigator<P extends ScreenParams>(
| React.Ref<NavigationContainerRef<ReactNavigation.RootParamList>>
| undefined
): JSX.Element {
const [primary, contrastPrimary] = useColor("primary");
const [secondary, _] = useColor("secondary");
const { screens, onStateChange, initialRouteName, ...navigatorProps } =
props;
const screenMap = screens.reduce((map, s) => {
Expand Down Expand Up @@ -117,13 +119,16 @@ function createStackNavigator<P extends ScreenParams>(
options={{
headerBackTitle: "",
headerBackTitleVisible: false,

headerTintColor: contrastPrimary,
headerStyle: {
backgroundColor: primary,
},
...options,
}}
/>
);
});
}, [screens]);
}, [screens, primary, contrastPrimary]);
return (
<NavigationContainer
ref={ref}
Expand All @@ -132,8 +137,12 @@ function createStackNavigator<P extends ScreenParams>(
theme={{
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: "#ffffff",
primary: primary,
background: contrastPrimary,
card: contrastPrimary,
text: primary,
border: contrastPrimary,
notification: secondary,
},
}}
>
Expand Down Expand Up @@ -197,10 +206,14 @@ const useNavigation = () => {

type Navigation = ReturnType<typeof useNavigation>;

function defineScreen<P>(path: string, component: React.ElementType<P>) {
function defineScreen<P extends ScreenParams>(
path: string,
component: React.ElementType<P>
): Screen<P> {
return {
path,
component,
options: {},
};
}

Expand Down
9 changes: 5 additions & 4 deletions expo/features/settings/theme/ThemeColorSelectorScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { StyleSheet, ScrollView } from "react-native";
import { Icon, ListItem } from "@rneui/themed";
import { defineScreen } from "@hpapp/features/root/protected/stack";
import {
defineScreen,
useScreenTitle,
} from "@hpapp/features/root/protected/stack";
import {
AvailableColors,
ColorScheme,
Expand All @@ -22,13 +25,11 @@ export default defineScreen(
title: string;
scheme: ColorScheme;
}) {
useScreenTitle(title);
const navigation = useNavigation();
const [config, updateConfig] = useLocalUserConfig();
const [_, updateTheme] = useAppTheme();
const [current] = useColor(scheme);
useEffect(() => {
navigation.setOptions({ title: title });
}, [title]);
return (
<ScrollView>
{AvailableColors.map((a) => {
Expand Down

0 comments on commit b23c877

Please sign in to comment.