Skip to content

Commit 2f8e59b

Browse files
committed
fix: support function components in withTheme
1 parent 5748ff5 commit 2f8e59b

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

docs/pages/3.theming.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,20 @@ Components wrapped with `withTheme` support the theme from the `Provider` as wel
105105

106106
## Customizing all instances of a component
107107

108-
Sometimes you want to style a component in a different way everywhere and don't want to change the properties in the theme so that other components are not affected. For example, say you want to change the font of all your buttons, but don't want to change `theme.fonts.medium` because it affects other components.
108+
Sometimes you want to style a component in a different way everywhere and don't want to change the properties in the theme so that other components are not affected. For example, say you want to change the font for all your buttons, but don't want to change `theme.fonts.medium` because it affects other components.
109109

110110
We don't have an API to do this, because you can already do it with components:
111111

112112
```js
113113
import * as React from 'react';
114114
import { Button } from 'react-native-paper';
115115

116-
export default function RoundButton(props) {
116+
export default function FancyButton(props) {
117117
return <Button theme={{ fonts: { medium: 'Open Sans' } }} {...props} />;
118118
}
119119
```
120120

121-
Now you can use `RoundButton` everywhere instead of using `Button`.
121+
Now you can use your `FancyButton` component everywhere instead of using `Button` from Paper.
122122

123123
## Gotchas
124124

src/components/Dialog/Dialog.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as React from 'react';
44
import { StyleSheet, Platform, Animated } from 'react-native';
55
import Modal from '../Modal';
6-
import { black, white } from '../../styles/colors';
6+
import { white } from '../../styles/colors';
77
import Paper from '../Paper';
88
import DialogActions from './DialogActions';
99
import DialogTitle from './DialogTitle';
@@ -138,12 +138,6 @@ class Dialog extends React.Component<Props, void> {
138138
}
139139
}
140140

141-
Dialog.defaultProps = {
142-
dismissable: true,
143-
titleColor: black,
144-
visible: false,
145-
};
146-
147141
export default withTheme(Dialog);
148142

149143
const styles = StyleSheet.create({

src/core/withTheme.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ const REACT_METHODS = [
3434
const isClassComponent = (Component: any) =>
3535
Boolean(Component.prototype && Component.prototype.isReactComponent);
3636

37-
export default function withTheme<P: {}, C: React.ComponentType<P>>(
37+
export default function withTheme<C: React.ComponentType<*>>(
3838
Comp: C
3939
): C &
40-
React.ComponentType<$Diff<P, { theme: Theme }> & { theme?: $Shape<Theme> }> {
40+
React.ComponentType<
41+
$Diff<React.ElementConfig<C>, { theme: Theme }> & { theme?: $Shape<Theme> }
42+
> {
4143
class ThemedComponent extends React.Component<*> {
42-
/* $FlowFixMe */
4344
static displayName = `withTheme(${Comp.displayName || Comp.name})`;
4445

4546
_previous: ?{ a: Theme, b: ?$Shape<Theme>, result: Theme };

0 commit comments

Comments
 (0)