|
| 1 | +// Type definitions for styled-components-react-native 5.1 |
| 2 | +// Project: https://github.com/styled-components/styled-components |
| 3 | +// Definitions by: Nathan Bierema <https://github.com/Methuselah96> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +// tslint:disable-next-line:no-single-declare-module |
| 7 | +declare module "styled-components/native" { |
| 8 | + import * as ReactNative from "react-native"; |
| 9 | + import * as React from "react"; |
| 10 | + |
| 11 | + export { |
| 12 | + css, |
| 13 | + DefaultTheme, |
| 14 | + isStyledComponent, |
| 15 | + ThemeConsumer, |
| 16 | + ThemeContext, |
| 17 | + ThemeProps, |
| 18 | + ThemeProvider, |
| 19 | + withTheme, |
| 20 | + useTheme, |
| 21 | + } from "styled-components"; |
| 22 | + |
| 23 | + import { |
| 24 | + AnyStyledComponent, |
| 25 | + DefaultTheme, |
| 26 | + isStyledComponent, |
| 27 | + StyledComponentInnerAttrs, |
| 28 | + StyledComponentInnerComponent, |
| 29 | + StyledComponentInnerOtherProps, |
| 30 | + ThemedCssFunction, |
| 31 | + ThemedStyledFunction, |
| 32 | + ThemedStyledInterface, |
| 33 | + ThemeProviderComponent, |
| 34 | + WithThemeFnInterface, |
| 35 | + } from "styled-components"; |
| 36 | + |
| 37 | + type AnyIfEmpty<T extends object> = keyof T extends never ? any : T; |
| 38 | + |
| 39 | + export type ReactNativeThemedStyledFunction< |
| 40 | + C extends React.ComponentType<any>, |
| 41 | + T extends object |
| 42 | + > = ThemedStyledFunction<C, T>; |
| 43 | + |
| 44 | + // Copied over from "ThemedBaseStyledInterface" in index.d.ts in order to remove DOM element typings |
| 45 | + interface ReactNativeThemedBaseStyledInterface<T extends object> { |
| 46 | + <C extends AnyStyledComponent>(component: C): ThemedStyledFunction< |
| 47 | + StyledComponentInnerComponent<C>, |
| 48 | + T, |
| 49 | + StyledComponentInnerOtherProps<C>, |
| 50 | + StyledComponentInnerAttrs<C> |
| 51 | + >; |
| 52 | + <C extends React.ComponentType<any>>( |
| 53 | + // unfortunately using a conditional type to validate that it can receive a `theme?: Theme` |
| 54 | + // causes tests to fail in TS 3.1 |
| 55 | + component: C |
| 56 | + ): ThemedStyledFunction<C, T>; |
| 57 | + } |
| 58 | + |
| 59 | + type ReactNativeThemedStyledInterface<T extends object> = ReactNativeThemedBaseStyledInterface<AnyIfEmpty<T>>; |
| 60 | + |
| 61 | + export interface ReactNativeStyledInterface<T extends object> extends ReactNativeThemedStyledInterface<T> { |
| 62 | + ActivityIndicator: ReactNativeThemedStyledFunction<typeof ReactNative.ActivityIndicator, T>; |
| 63 | + ActivityIndicatorIOS: ReactNativeThemedStyledFunction<typeof ReactNative.ActivityIndicator, T>; |
| 64 | + Button: ReactNativeThemedStyledFunction<typeof ReactNative.Button, T>; |
| 65 | + DatePickerIOS: ReactNativeThemedStyledFunction<typeof ReactNative.DatePickerIOS, T>; |
| 66 | + DrawerLayoutAndroid: ReactNativeThemedStyledFunction<typeof ReactNative.DrawerLayoutAndroid, T>; |
| 67 | + Image: ReactNativeThemedStyledFunction<typeof ReactNative.Image, T>; |
| 68 | + ImageBackground: ReactNativeThemedStyledFunction<typeof ReactNative.ImageBackground, T>; |
| 69 | + KeyboardAvoidingView: ReactNativeThemedStyledFunction<typeof ReactNative.KeyboardAvoidingView, T>; |
| 70 | + ListView: ReactNativeThemedStyledFunction<typeof ReactNative.ListView, T>; |
| 71 | + Modal: ReactNativeThemedStyledFunction<typeof ReactNative.Modal, T>; |
| 72 | + NavigatorIOS: ReactNativeThemedStyledFunction<typeof ReactNative.NavigatorIOS, T>; |
| 73 | + Picker: ReactNativeThemedStyledFunction<typeof ReactNative.Picker, T>; |
| 74 | + PickerIOS: ReactNativeThemedStyledFunction<typeof ReactNative.PickerIOS, T>; |
| 75 | + ProgressBarAndroid: ReactNativeThemedStyledFunction<typeof ReactNative.ProgressBarAndroid, T>; |
| 76 | + ProgressViewIOS: ReactNativeThemedStyledFunction<typeof ReactNative.ProgressViewIOS, T>; |
| 77 | + ScrollView: ReactNativeThemedStyledFunction<typeof ReactNative.ScrollView, T>; |
| 78 | + SegmentedControlIOS: ReactNativeThemedStyledFunction<typeof ReactNative.SegmentedControlIOS, T>; |
| 79 | + Slider: ReactNativeThemedStyledFunction<typeof ReactNative.Slider, T>; |
| 80 | + SliderIOS: ReactNativeThemedStyledFunction<typeof ReactNative.Slider, T>; |
| 81 | + SnapshotViewIOS: ReactNativeThemedStyledFunction<typeof ReactNative.SnapshotViewIOS, T>; |
| 82 | + Switch: ReactNativeThemedStyledFunction<typeof ReactNative.Switch, T>; |
| 83 | + RecyclerViewBackedScrollView: ReactNativeThemedStyledFunction< |
| 84 | + typeof ReactNative.RecyclerViewBackedScrollView, |
| 85 | + T |
| 86 | + >; |
| 87 | + RefreshControl: ReactNativeThemedStyledFunction<typeof ReactNative.RefreshControl, T>; |
| 88 | + SafeAreaView: ReactNativeThemedStyledFunction<typeof ReactNative.SafeAreaView, T>; |
| 89 | + StatusBar: ReactNativeThemedStyledFunction<typeof ReactNative.StatusBar, T>; |
| 90 | + SwipeableListView: ReactNativeThemedStyledFunction<typeof ReactNative.SwipeableListView, T>; |
| 91 | + SwitchAndroid: ReactNativeThemedStyledFunction<typeof ReactNative.Switch, T>; |
| 92 | + SwitchIOS: ReactNativeThemedStyledFunction<typeof ReactNative.SwitchIOS, T>; |
| 93 | + TabBarIOS: ReactNativeThemedStyledFunction<typeof ReactNative.TabBarIOS, T>; |
| 94 | + Text: ReactNativeThemedStyledFunction<typeof ReactNative.Text, T>; |
| 95 | + TextInput: ReactNativeThemedStyledFunction<typeof ReactNative.TextInput, T>; |
| 96 | + ToolbarAndroid: ReactNativeThemedStyledFunction<typeof ReactNative.ToolbarAndroid, T>; |
| 97 | + TouchableHighlight: ReactNativeThemedStyledFunction<typeof ReactNative.TouchableHighlight, T>; |
| 98 | + TouchableNativeFeedback: ReactNativeThemedStyledFunction<typeof ReactNative.TouchableNativeFeedback, T>; |
| 99 | + TouchableOpacity: ReactNativeThemedStyledFunction<typeof ReactNative.TouchableOpacity, T>; |
| 100 | + TouchableWithoutFeedback: ReactNativeThemedStyledFunction<typeof ReactNative.TouchableWithoutFeedback, T>; |
| 101 | + View: ReactNativeThemedStyledFunction<typeof ReactNative.View, T>; |
| 102 | + ViewPagerAndroid: ReactNativeThemedStyledFunction<typeof ReactNative.ViewPagerAndroid, T>; |
| 103 | + FlatList: ReactNativeThemedStyledFunction<typeof ReactNative.FlatList, T>; |
| 104 | + SectionList: ReactNativeThemedStyledFunction<typeof ReactNative.SectionList, T>; |
| 105 | + } |
| 106 | + |
| 107 | + export interface ReactNativeThemedStyledComponentsModule<T extends object, U extends object = T> { |
| 108 | + default: ReactNativeStyledInterface<T>; |
| 109 | + |
| 110 | + css: ThemedCssFunction<T>; |
| 111 | + |
| 112 | + withTheme: WithThemeFnInterface<T>; |
| 113 | + ThemeProvider: ThemeProviderComponent<T, U>; |
| 114 | + ThemeConsumer: React.Consumer<T>; |
| 115 | + ThemeContext: React.Context<T>; |
| 116 | + useTheme(): T; |
| 117 | + |
| 118 | + // This could be made to assert `target is StyledComponent<any, T>` instead, but that feels not type safe |
| 119 | + isStyledComponent: typeof isStyledComponent; |
| 120 | + } |
| 121 | + |
| 122 | + const styled: ReactNativeStyledInterface<DefaultTheme>; |
| 123 | + |
| 124 | + export default styled; |
| 125 | +} |
0 commit comments