Skip to content

Commit f0a75fc

Browse files
withTheme -> themed (#11 by @jamonholmgren)
We are now using `themed(...)` to handle dark/light mode. --------- Signed-off-by: Robin Heinze <robin@infinite.red> Co-authored-by: Robin Heinze <robin@infinite.red> Co-authored-by: Robin Heinze <robin.m.heinze@gmail.com>
1 parent 3973a07 commit f0a75fc

29 files changed

+371
-390
lines changed

app/app.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import { StatusBar, View, type ViewStyle } from "react-native"
88
import { connectToServer } from "./state/connectToServer"
9-
import { useTheme, useThemeName, withTheme } from "./theme/theme"
9+
import { useTheme, themed } from "./theme/theme"
1010
import { useEffect } from "react"
1111
import { TimelineScreen } from "./screens/TimelineScreen"
1212
import { AppHeader } from "./components/AppHeader"
@@ -24,8 +24,7 @@ const menuConfig = {
2424
}
2525

2626
function App(): React.JSX.Element {
27-
const [theme] = useThemeName()
28-
const { colors } = useTheme(theme)
27+
const { colors } = useTheme()
2928

3029
useMenuItem(menuConfig)
3130

@@ -43,24 +42,24 @@ function App(): React.JSX.Element {
4342
useEffect(() => connectToServer(), [])
4443

4544
return (
46-
<View style={$container(theme)}>
45+
<View style={$container()}>
4746
<Titlebar />
4847
<StatusBar barStyle={"dark-content"} backgroundColor={colors.background} />
4948
<AppHeader />
50-
<View style={$contentContainer(theme)}>
49+
<View style={$contentContainer}>
5150
<TimelineScreen />
5251
</View>
5352
</View>
5453
)
5554
}
5655

57-
const $container = withTheme<ViewStyle>(({ colors }) => ({
56+
const $container = themed<ViewStyle>(({ colors }) => ({
5857
flex: 1,
5958
backgroundColor: colors.background,
6059
}))
6160

62-
const $contentContainer = withTheme<ViewStyle>(({ spacing }) => ({
61+
const $contentContainer: ViewStyle = {
6362
flex: 1,
64-
}))
63+
}
6564

6665
export default App

app/components/ActionButton.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GestureResponderEvent, TouchableOpacity, ViewStyle } from "react-native"
2-
import { useThemeName, withTheme } from "../theme/theme"
2+
import { themed } from "../theme/theme"
33

44
interface ActionButtonProps {
55
icon: React.ElementType<{ size: number }>
@@ -8,16 +8,14 @@ interface ActionButtonProps {
88
}
99

1010
function ActionButton({ icon: Icon, onClick, style }: ActionButtonProps) {
11-
const [theme] = useThemeName()
12-
1311
return (
14-
<TouchableOpacity style={[$container(theme), style]} onPress={onClick} activeOpacity={0.7}>
12+
<TouchableOpacity style={[$container(), style]} onPress={onClick} activeOpacity={0.7}>
1513
<Icon size={24} />
1614
</TouchableOpacity>
1715
)
1816
}
1917

20-
const $container = withTheme<ViewStyle>(({ spacing }) => ({
18+
const $container = themed<ViewStyle>(({ spacing }) => ({
2119
marginHorizontal: spacing.sm,
2220
padding: spacing.sm,
2321
justifyContent: "center",

app/components/AppHeader.tsx

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ClearLogsButton } from "./ClearLogsButton"
1010
import { ClientTab } from "./ClientTab"
1111
import Header from "./Header"
1212
import { HeaderTitle } from "./HeaderTitle"
13-
import { useThemeName, withTheme } from "../theme/theme"
13+
import { useThemeName, themed } from "../theme/theme"
1414
import { useGlobal } from "../state/useGlobal"
1515
import { getReactotronAppId } from "../state/connectToServer"
1616

@@ -24,31 +24,26 @@ export function AppHeader() {
2424

2525
return (
2626
<Header>
27-
<View style={$tabContainer(theme)}>
27+
<View style={$tabContainer()}>
2828
{clientIds.map((id) => (
2929
<ClientTab key={id} clientId={id} />
3030
))}
3131
</View>
3232
<HeaderTitle title={`Reactotron ${reactotronAppId}`} />
33-
<View style={$statusRow(theme)}>
33+
<View style={$statusRow()}>
3434
<View>
35-
<TextInput value={"SEARCHING"} placeholder="Search" style={{ width: 100 }} />
35+
<TextInput value={"SEARCHING"} placeholder="Search" style={$searchInput} />
3636
<Text>Search</Text>
3737
</View>
38-
<View style={$statusItem(theme)}>
39-
<View
40-
style={[
41-
$dot(theme),
42-
error ? $dotRed(theme) : isConnected ? $dotGreen(theme) : $dotGray(theme),
43-
]}
44-
/>
45-
<Text style={$statusText(theme)}>Server</Text>
38+
<View style={$statusItem()}>
39+
<View style={[$dot(), error ? $dotRed() : isConnected ? $dotGreen() : $dotGray()]} />
40+
<Text style={$statusText()}>Server</Text>
4641
<ClearLogsButton />
4742
</View>
48-
<View style={$divider(theme)} />
49-
<View style={$statusItem(theme)}>
50-
<View style={[$dot(theme), arch === "Fabric" ? $dotGreen(theme) : $dotOrange(theme)]} />
51-
<Text style={$statusText(theme)}>{arch}</Text>
43+
<View style={$divider()} />
44+
<View style={$statusItem()}>
45+
<View style={[$dot(), arch === "Fabric" ? $dotGreen() : $dotOrange()]} />
46+
<Text style={$statusText()}>{arch}</Text>
5247
</View>
5348
</View>
5449
<ActionButton
@@ -61,49 +56,51 @@ export function AppHeader() {
6156
)
6257
}
6358

64-
const $tabContainer = withTheme<ViewStyle>(({ spacing }) => ({
59+
const $tabContainer = themed<ViewStyle>(({ spacing }) => ({
6560
flexDirection: "row",
6661
paddingHorizontal: spacing.xl,
6762
paddingVertical: spacing.md,
6863
gap: spacing.md,
6964
}))
7065

71-
const $statusRow = withTheme<ViewStyle>(({ spacing }) => ({
66+
const $statusRow = themed<ViewStyle>(({ spacing }) => ({
7267
flexDirection: "row",
7368
alignItems: "center",
7469
padding: spacing.sm,
7570
justifyContent: "center",
7671
}))
7772

78-
const $statusItem = withTheme<ViewStyle>(() => ({
73+
const $statusItem = themed<ViewStyle>(() => ({
7974
flexDirection: "row",
8075
alignItems: "center",
8176
minWidth: 80,
8277
}))
8378

84-
const $divider = withTheme<ViewStyle>(({ colors, spacing }) => ({
79+
const $divider = themed<ViewStyle>(({ colors, spacing }) => ({
8580
width: 1,
8681
height: 24,
8782
backgroundColor: colors.border,
8883
marginHorizontal: spacing.md,
8984
borderRadius: 1,
9085
}))
9186

92-
const $dot = withTheme<ViewStyle>(({ colors }) => ({
87+
const $dot = themed<ViewStyle>(({ colors }) => ({
9388
width: 12,
9489
height: 12,
9590
borderRadius: 6,
9691
marginRight: 8,
9792
borderWidth: 1,
9893
borderColor: colors.border,
9994
}))
100-
const $dotGray = withTheme<ViewStyle>(({ colors }) => ({ backgroundColor: colors.neutral }))
101-
const $dotGreen = withTheme<ViewStyle>(({ colors }) => ({ backgroundColor: colors.success }))
102-
const $dotRed = withTheme<ViewStyle>(({ colors }) => ({ backgroundColor: colors.danger }))
103-
const $dotOrange = withTheme<ViewStyle>(({ colors }) => ({ backgroundColor: colors.primary }))
95+
const $dotGray = themed<ViewStyle>(({ colors }) => ({ backgroundColor: colors.neutral }))
96+
const $dotGreen = themed<ViewStyle>(({ colors }) => ({ backgroundColor: colors.success }))
97+
const $dotRed = themed<ViewStyle>(({ colors }) => ({ backgroundColor: colors.danger }))
98+
const $dotOrange = themed<ViewStyle>(({ colors }) => ({ backgroundColor: colors.primary }))
10499

105-
const $statusText = withTheme<TextStyle>(({ colors }) => ({
100+
const $statusText = themed<TextStyle>(({ colors }) => ({
106101
fontSize: 16,
107102
color: colors.mainText,
108103
fontWeight: "600",
109104
}))
105+
106+
const $searchInput: ViewStyle = { width: 100 }

app/components/ClientTab.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type { ClientData } from "../types"
22
import { useGlobal } from "../state/useGlobal"
3-
import { useThemeName, withTheme } from "../theme/theme"
3+
import { themed } from "../theme/theme"
44
import { Pressable, Text, TextStyle, ViewStyle } from "react-native"
55

66
const tabgroup = "activeClientId"
77

88
export function ClientTab({ clientId }: { clientId: string }) {
9-
const [theme] = useThemeName()
109
const [clientData] = useGlobal<ClientData>(`client-${clientId}`, {} as ClientData)
1110

1211
const label: string = (clientData?.name ?? clientId) + "\n"
@@ -16,32 +15,32 @@ export function ClientTab({ clientId }: { clientId: string }) {
1615
const active = activeTab === label
1716

1817
return (
19-
<Pressable key={clientId} onPress={() => setActiveTab(label)} style={$container(theme)}>
20-
<Text style={[$tab(theme), active ? $tabActive(theme) : {}]}>{label}</Text>
21-
<Text style={$os(theme)}>{os}</Text>
18+
<Pressable key={clientId} onPress={() => setActiveTab(label)} style={$container()}>
19+
<Text style={[$tab(), active ? $tabActive() : {}]}>{label}</Text>
20+
<Text style={$os()}>{os}</Text>
2221
</Pressable>
2322
)
2423
}
2524

26-
const $container = withTheme<ViewStyle>(({ spacing }) => ({
25+
const $container = themed<ViewStyle>(({ spacing }) => ({
2726
flexDirection: "column",
2827
alignItems: "flex-start",
2928
gap: spacing.xxs,
3029
cursor: "pointer",
3130
}))
3231

33-
const $tab = withTheme<TextStyle>(({ spacing, colors }) => ({
32+
const $tab = themed<TextStyle>(({ spacing, colors }) => ({
3433
fontSize: spacing.md,
3534
color: colors.mainText,
3635
}))
3736

38-
const $tabActive = withTheme<TextStyle>(({ colors }) => ({
37+
const $tabActive = themed<TextStyle>(({ colors }) => ({
3938
borderBottomColor: colors.primary,
4039
color: colors.mainText,
4140
textDecorationLine: "underline",
4241
}))
4342

44-
const $os = withTheme<TextStyle>(({ colors }) => ({
43+
const $os = themed<TextStyle>(({ colors }) => ({
4544
fontSize: 12,
4645
color: colors.mainText,
4746
}))

0 commit comments

Comments
 (0)