Skip to content

Instantly share code, notes, and snippets.

@ScreamZ
Last active September 16, 2019 12:01
Show Gist options
  • Save ScreamZ/38a1df62e457b3b3632948c466534051 to your computer and use it in GitHub Desktop.
Save ScreamZ/38a1df62e457b3b3632948c466534051 to your computer and use it in GitHub Desktop.
A working Typescript configuration for styled-components and React Native
import React, { useRef } from "react";
import { ThemeProvider } from "styled-components/native";
import AppNavigator from "@modules/navigation/AppNavigator";
import { theme } from "@modules/ui/theme";
function App() {
return (
<ThemeProvider theme={theme}>
<AppNavigator />
</ThemeProvider>
);
}
export default App;
// import original module declarations
import "styled-components/native";
import { DefaultTheme } from "styled-components/native";
// and extend them!
declare module "styled-components" {
export interface DefaultTheme {
colors: {
main: string;
lightGrey: string;
white: string;
};
spacing: {
tiny: number;
small: number;
medium: number;
large: number;
};
}
}
// Export theme implementing interface
export const theme: DefaultTheme = {
colors: {
main: "rgb(0, 136, 102)",
lightGrey: "rgb(162, 162, 162)",
white: "white",
},
spacing: {
large: 30,
medium: 20,
small: 15,
tiny: 10,
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment