-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing export of composeRestyleFunctions
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
## Migrating to restyle v2 | ||
|
||
v2 of this library introduces breaking changes in the usage of the `useRestyle` hook. | ||
If you are not using `useRestyle` in your project, then you don't need to address any breaking change and can upgrade the library right away. | ||
|
||
## Addressing breaking changes in `useRestyle` | ||
|
||
1. Import `composeRestyleFunctions` from `@shopify/restyle` | ||
2. Wrap the array you were using as param of `useRestyle` with `composeRestyleFunctions` | ||
3. Done | ||
|
||
### Before | ||
|
||
```tsx | ||
import {TouchableOpacity, View} from 'react-native'; | ||
import { | ||
useRestyle, | ||
spacing, | ||
border, | ||
backgroundColor, | ||
SpacingProps, | ||
BorderProps, | ||
BackgroundColorProps, | ||
} from '@shopify/restyle'; | ||
|
||
import Text from './Text'; | ||
import {Theme} from './theme'; | ||
|
||
const restyleFunctions = [spacing, border, backgroundColor]; | ||
type Props = SpacingProps<Theme> & | ||
BorderProps<Theme> & | ||
BackgroundColorProps<Theme> & { | ||
onPress: () => void; | ||
}; | ||
|
||
const Button = ({onPress, label, ...rest}: Props) => { | ||
const props = useRestyle(restyleFunctions, rest); | ||
|
||
return ( | ||
<TouchableOpacity onPress={onPress}> | ||
<View {...props}> | ||
<Text variant="buttonLabel">{label}</Text> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
``` | ||
|
||
### After | ||
|
||
```tsx | ||
import {TouchableOpacity, View} from 'react-native'; | ||
import { | ||
useRestyle, | ||
spacing, | ||
border, | ||
backgroundColor, | ||
SpacingProps, | ||
BorderProps, | ||
BackgroundColorProps, | ||
composeRestyleFunctions, | ||
} from '@shopify/restyle'; | ||
|
||
import Text from './Text'; | ||
import {Theme} from './theme'; | ||
|
||
const restyleFunctions = composeRestyleFunctions([ | ||
spacing, | ||
border, | ||
backgroundColor, | ||
]); | ||
type Props = SpacingProps<Theme> & | ||
BorderProps<Theme> & | ||
BackgroundColorProps<Theme> & { | ||
onPress: () => void; | ||
}; | ||
|
||
const Button = ({onPress, label, ...rest}: Props) => { | ||
const props = useRestyle(restyleFunctions, rest); | ||
|
||
return ( | ||
<TouchableOpacity onPress={onPress}> | ||
<View {...props}> | ||
<Text variant="buttonLabel">{label}</Text> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters