-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emotion Native #759
Emotion Native #759
Changes from all commits
6b9f575
91380c2
38d3012
db3d964
d545607
6ec1ff3
94b0c28
25d75bc
ae75fe3
b80e73f
fc1beb9
ddb2dd2
ee2181c
f839c70
95c28d3
47f5035
fdc1876
abca5e7
c656626
b967b7d
2cf1a06
1073a66
341e192
f427e40
f8483e2
fdaf228
00881d1
df1d259
be12b5c
6a1b33b
32b27c1
f87c05d
975bc68
4f3f998
4e8ca76
8c6694e
84c1bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @flow | ||
/* eslint-env jest */ | ||
|
||
let components = [ | ||
'ActivityIndicator', | ||
'ActivityIndicatorIOS', | ||
'ART', | ||
'Button', | ||
'DatePickerIOS', | ||
'DrawerLayoutAndroid', | ||
'Image', | ||
'ImageBackground', | ||
'ImageEditor', | ||
'ImageStore', | ||
'KeyboardAvoidingView', | ||
'ListView', | ||
'MapView', | ||
'Modal', | ||
'NavigatorIOS', | ||
'Picker', | ||
'PickerIOS', | ||
'ProgressBarAndroid', | ||
'ProgressViewIOS', | ||
'ScrollView', | ||
'SegmentedControlIOS', | ||
'Slider', | ||
'SliderIOS', | ||
'SnapshotViewIOS', | ||
'Switch', | ||
'RecyclerViewBackedScrollView', | ||
'RefreshControl', | ||
'SafeAreaView', | ||
'StatusBar', | ||
'SwipeableListView', | ||
'SwitchAndroid', | ||
'SwitchIOS', | ||
'TabBarIOS', | ||
'Text', | ||
'TextInput', | ||
'ToastAndroid', | ||
'ToolbarAndroid', | ||
'Touchable', | ||
'TouchableHighlight', | ||
'TouchableNativeFeedback', | ||
'TouchableOpacity', | ||
'TouchableWithoutFeedback', | ||
'View', | ||
'ViewPagerAndroid', | ||
'WebView', | ||
'FlatList', | ||
'SectionList', | ||
'VirtualizedList' | ||
] | ||
|
||
module.exports = { | ||
...jest.requireActual('react-primitives'), | ||
...components.reduce((obj, key) => { | ||
obj[key] = key | ||
return obj | ||
}, {}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @flow | ||
/* eslint-env jest */ | ||
module.exports = { | ||
...jest.requireActual('react-primitives'), | ||
View: 'View', | ||
Image: 'Image', | ||
Text: 'Text' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
# @emotion/native | ||
|
||
> Style and render React Native components using emotion | ||
|
||
## Install | ||
|
||
``` | ||
npm install @emotion/native | ||
``` | ||
|
||
or if you use yarn | ||
|
||
``` | ||
yarn add @emotion/native | ||
``` | ||
|
||
This package also depends on `react`, `react-native` and `prop-types` so make sure you've them installed. | ||
|
||
## Example | ||
|
||
```js | ||
import React from 'react' | ||
import { AppRegistry } from 'react-native'; | ||
import styled, { css } from '@emotion/native' | ||
|
||
const Container = styled.View` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin: 50px; | ||
` | ||
|
||
const Description = styled.Text({ | ||
color: 'hotpink' | ||
}) | ||
|
||
const Image = styled.Image` | ||
padding: 40px; | ||
` | ||
|
||
const emotionLogo = | ||
'https://cdn.rawgit.com/emotion-js/emotion/master/emotion.png' | ||
|
||
class App extends React.Component { | ||
render() { | ||
return ( | ||
<Container | ||
style={css` | ||
border-radius: 10px; | ||
`} | ||
> | ||
<Description style={{ fontSize: 45, fontWeight: 'bold' }}> | ||
Emotion Primitives | ||
</Description> | ||
<Image | ||
source={{ | ||
uri: emotionLogo, | ||
height: 150, | ||
width: 150 | ||
}} | ||
/> | ||
</Container> | ||
) | ||
} | ||
} | ||
|
||
AppRegistry.registerComponent('ExampleApp', () => App); | ||
``` | ||
|
||
## Theming | ||
|
||
Use `emotion-theming` for theming support. | ||
|
||
```js | ||
import React from 'react' | ||
import styled, { css } from '@emotion/native' | ||
|
||
import { ThemeProvider } from 'emotion-theming' | ||
|
||
const theme = { | ||
color: 'hotpink', | ||
backgroundColor: 'purple' | ||
} | ||
|
||
const Container = styled.View` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin: 50px; | ||
border: 5px solid red; | ||
background-color: ${props => props.theme.backgroundColor}; | ||
` | ||
|
||
const Description = styled.Text({ | ||
color: 'hotpink' | ||
}) | ||
|
||
const Image = styled.Image` | ||
padding: 40px; | ||
` | ||
|
||
const emotionLogo = | ||
'https://cdn.rawgit.com/emotion-js/emotion/master/emotion.png' | ||
|
||
class App extends React.Component { | ||
render() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Container | ||
style={css` | ||
border-radius: 10px; | ||
`} | ||
> | ||
<Description style={{ fontSize: 45, fontWeight: 'bold' }}> | ||
Emotion Primitives | ||
</Description> | ||
<Image | ||
source={{ | ||
uri: emotionLogo, | ||
height: 150, | ||
width: 150 | ||
}} | ||
/> | ||
</Container> | ||
</ThemeProvider> | ||
) | ||
} | ||
} | ||
``` | ||
|
||
## Usage with `react-360` | ||
|
||
`@emotion/native` can also be used with `react-360` for styling VR applications. Check out [this](https://facebook.github.io/react-360/docs/setup.html) guide for setting up a `react-360` project. | ||
|
||
### Example | ||
|
||
```js | ||
import React from 'react'; | ||
import { AppRegistry, StyleSheet, Text, View } from 'react-360'; | ||
import styled from '@emotion/native'; | ||
|
||
const StyledName = styled.Text` | ||
font-size: 40px; | ||
color: hotpink; | ||
`; | ||
|
||
export default class App extends React.Component { | ||
render() { | ||
return ( | ||
<View style={styles.panel}> | ||
<View style={styles.greetingBox}> | ||
<StyledName>Emotion Native</StyledName> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
panel: { | ||
// Fill the entire surface | ||
width: 1000, | ||
height: 600, | ||
backgroundColor: 'rgba(255, 255, 255, 0.4)', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
greetingBox: { | ||
padding: 20, | ||
backgroundColor: '#000000', | ||
borderColor: '#639dda', | ||
borderWidth: 2, | ||
}, | ||
greeting: { | ||
fontSize: 30, | ||
}, | ||
}); | ||
|
||
AppRegistry.registerComponent('App', () => App); | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@emotion/native", | ||
"version": "1.0.0", | ||
"description": "Style and render React Native components using emotion", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"files": ["src", "dist"], | ||
"devDependencies": { | ||
"emotion-theming": "^9.2.5", | ||
"react": "^16.4.1", | ||
"react-native": "^0.56.0" | ||
}, | ||
"dependencies": { | ||
"@emotion/primitives-core": "1.0.0" | ||
}, | ||
"peerDependencies": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt a peer on react be here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! Done ✅ |
||
"prop-types": "15.x", | ||
"react": "15.x || 16.x", | ||
"react-native": ">=0.14.0 && < 1" | ||
}, | ||
"homepage": "https://emotion.sh", | ||
"license": "MIT", | ||
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/native", | ||
"keywords": ["styles", "emotion", "react", "css", "css-in-js", "native"], | ||
"bugs": { | ||
"url": "https://github.com/emotion-js/emotion/issues" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import reactNative from 'react-native' | ||
import { createCss } from '@emotion/primitives-core' | ||
|
||
import { styled } from './styled' | ||
|
||
const css = createCss(reactNative.StyleSheet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be annotated with PURE |
||
|
||
const components = [ | ||
'ActivityIndicator', | ||
'ActivityIndicatorIOS', | ||
'ART', | ||
'Button', | ||
'DatePickerIOS', | ||
'DrawerLayoutAndroid', | ||
'Image', | ||
'ImageBackground', | ||
'ImageEditor', | ||
'ImageStore', | ||
'KeyboardAvoidingView', | ||
'ListView', | ||
'MapView', | ||
'Modal', | ||
'NavigatorIOS', | ||
'Picker', | ||
'PickerIOS', | ||
'ProgressBarAndroid', | ||
'ProgressViewIOS', | ||
'ScrollView', | ||
'SegmentedControlIOS', | ||
'Slider', | ||
'SliderIOS', | ||
'SnapshotViewIOS', | ||
'Switch', | ||
'RecyclerViewBackedScrollView', | ||
'RefreshControl', | ||
'SafeAreaView', | ||
'StatusBar', | ||
'SwipeableListView', | ||
'SwitchAndroid', | ||
'SwitchIOS', | ||
'TabBarIOS', | ||
'Text', | ||
'TextInput', | ||
'ToastAndroid', | ||
'ToolbarAndroid', | ||
'Touchable', | ||
'TouchableHighlight', | ||
'TouchableNativeFeedback', | ||
'TouchableOpacity', | ||
'TouchableWithoutFeedback', | ||
'View', | ||
'ViewPagerAndroid', | ||
'WebView', | ||
'FlatList', | ||
'SectionList', | ||
'VirtualizedList' | ||
] | ||
|
||
export { css } | ||
|
||
export default components.reduce( | ||
(acc, comp) => | ||
Object.defineProperty(acc, comp, { | ||
enumerable: true, | ||
configurable: false, | ||
get() { | ||
return styled(reactNative[comp]) | ||
} | ||
}), | ||
styled | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { StyleSheet } from 'react-native' | ||
import { createStyled } from '@emotion/primitives-core' | ||
|
||
/** | ||
* a function that returns a styled component which render styles in React Native | ||
*/ | ||
let styled = createStyled(StyleSheet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also a good candidate for PURE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there any side-effects of using PURE here ? |
||
|
||
export { styled } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is different here than in other examples (in this file), this could be enforced with prettier + lint-staged on precommit hook (with husky) as it can handle
.md
too, cc @mitchellhamiltonThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be great. This will also resolve all the formatting issues!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andarist If you could submit a PR for it, that would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to remember to do that later :)