-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,214 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
# All files | ||
[*] | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
|
||
# JS files | ||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# JSON files | ||
[*.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# Java files | ||
[*.java] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Objective C files | ||
[*{.h,.m,.mm}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,6 @@ | ||
**/dist/* | ||
**/node_modules/* | ||
**/server.js | ||
**/webpack.config*.js | ||
**/test-utils/setup.js | ||
|
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,22 @@ | ||
{ | ||
"extends": "airbnb", | ||
"env": { | ||
"mocha": true | ||
}, | ||
"plugins": [ | ||
"react-native" | ||
], | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"no-empty-label": 0, | ||
"no-console": 0, | ||
"import/no-unresolved": 0, | ||
"global-require": 0, | ||
"no-underscore-dangle": 0, | ||
"space-before-keywords": 0, | ||
"space-after-keywords": 0, | ||
"space-return-throw-case": 0, | ||
"react-native/no-unused-styles": 2, | ||
"react-native/split-platform-components": 2 | ||
} | ||
} |
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,8 @@ | ||
# Node | ||
node_modules/ | ||
|
||
# Npm | ||
*.tgz | ||
|
||
# WebStorm | ||
.idea |
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,16 @@ | ||
# Node | ||
node_modules | ||
|
||
# WebStorm | ||
.idea | ||
|
||
# Ignore test folders | ||
*_tests_ | ||
|
||
# Ignore local/config files | ||
.editorconfig | ||
.npmignore | ||
.gitignore | ||
|
||
# Ignore previous builds | ||
*.tgz |
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,24 @@ | ||
BSD License | ||
For @shoutem/theme software | ||
Copyright (c) 2016-present, Shoutem | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Shoutem nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,157 @@ | ||
# Theme | ||
|
||
The React Native component's style is usually defined as a static variable along with the component itself. This makes it easy to build self contained components that always look and behave in the same way. On the other hand, it complicates building themeable (or skinnable) components that could have multiple styles that can be customized without touching the component source code. | ||
`@shoutem/theme` is built to address that problem. With themes, you can target specific components in your app and customize them through one file, just like you would do it with CSS on the web. | ||
|
||
## Install | ||
|
||
```bash | ||
$ npm install --save @shoutem/theme | ||
``` | ||
|
||
## Docs | ||
|
||
All the documentation is available on the [Developer portal](http://shoutem.github.io/docs/ui-toolkit/theme/introduction). | ||
|
||
## Examples | ||
|
||
Use [Shoutem UI](https://github.com/shoutem.theme), set of components which are made to be customizable by Theme, to see how to work with it. | ||
|
||
Create new React Native project: | ||
|
||
```bash | ||
$ react-native init HelloWorld | ||
``` | ||
|
||
Install `@shoutem/ui` and `@shoutem/theme` and link them in your project: | ||
|
||
```bash | ||
$ cd HelloWorld | ||
$ npm install --save @shoutem/ui | ||
$ npm install --save @shoutem/theme | ||
$ rnpm link | ||
``` | ||
|
||
Now, simply copy the following to your `index.ios.js` file of React Native project: | ||
|
||
```JavaScript | ||
import React, { Component } from 'react'; | ||
import { AppRegistry, Dimensions } from 'react-native'; | ||
import { StyleProvider } from '@shoutem/theme'; | ||
import { | ||
Card, | ||
Image, | ||
View, | ||
Subtitle, | ||
Caption, | ||
} from '@shoutem/ui'; | ||
|
||
const window = Dimensions.get('window'); | ||
|
||
const Colors = { | ||
BACKGROUND: '#ffffff', | ||
SHADOW: '#000000', | ||
}; | ||
|
||
const MEDIUM_GUTTER = 15; | ||
|
||
const theme = { | ||
'shoutem.ui.View': { | ||
'.h-center': { | ||
alignItems: 'center', | ||
}, | ||
|
||
'.v-center': { | ||
justifyContent: 'center', | ||
}, | ||
|
||
'.flexible': { | ||
flex: 1, | ||
}, | ||
|
||
flexDirection: 'column', | ||
}, | ||
|
||
'shoutem.ui.Card': { | ||
'shoutem.ui.View.content': { | ||
'shoutem.ui.Subtitle': { | ||
marginBottom: MEDIUM_GUTTER, | ||
}, | ||
|
||
flex: 1, | ||
alignSelf: 'stretch', | ||
padding: 10, | ||
}, | ||
|
||
width: (180 / 375) * window.width, | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'flex-start', | ||
backgroundColor: Colors.BACKGROUND, | ||
borderRadius: 2, | ||
shadowColor: Colors.SHADOW, | ||
shadowOpacity: 0.1, | ||
shadowOffset: { width: 1, height: 1 }, | ||
}, | ||
|
||
'shoutem.ui.Image': { | ||
'.medium-wide': { | ||
width: (180 / 375) * window.width, | ||
height: 85, | ||
}, | ||
|
||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
resizeMode: 'cover', | ||
backgroundColor: Colors.BACKGROUND, | ||
}, | ||
}; | ||
|
||
class HelloWorld extends Component { | ||
render() { | ||
return ( | ||
<StyleProvider style={theme}> | ||
<View styleName="flexible vertical v-center h-center"> | ||
<Card> | ||
<Image | ||
styleName="medium-wide" | ||
source={{ uri: 'http://shoutem.github.io/img/ui-toolkit/examples/image-12.png' }} | ||
/> | ||
<View styleName="content"> | ||
<Subtitle numberOfLines={4}> | ||
Lady Gaga Sings National Anthem at Super Bowl 50 | ||
</Subtitle> | ||
<Caption>21 hours ago</Caption> | ||
</View> | ||
</Card> | ||
</View> | ||
</StyleProvider> | ||
); | ||
} | ||
} | ||
|
||
AppRegistry.registerComponent('HelloWorld', () => HelloWorld); | ||
``` | ||
|
||
Finally, run the app! | ||
|
||
```bash | ||
$ react-native run-ios | ||
``` | ||
|
||
## UI Toolkit | ||
|
||
Shoutem UI is a part of the Shoutem UI Toolkit that enables you to build professionally looking React Native apps with ease. | ||
|
||
It consists of three libraries: | ||
|
||
- [@shoutem/ui](https://github.com/shoutem/ui): beautiful and customizable UI components | ||
- [@shoutem/theme](https://github.com/shoutem/theme): “CSS-way" of styling entire app | ||
- [@shoutem/animation](https://github.com/shoutem/animation): declarative way of applying ready-made animations | ||
|
||
|
||
## License | ||
|
||
[The BSD License](https://opensource.org/licenses/BSD-3-Clause) | ||
Copyright (c) 2016-present, [Shoutem](http://shoutem.github.io) |
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,66 @@ | ||
import { assert } from 'chai'; | ||
import StyleNormalizer from '../src/StyleNormalizer/StyleNormalizer'; | ||
import { | ||
SIDES, | ||
CORNERS, | ||
HORIZONTAL, | ||
VERTICAL, | ||
} from '../src/StyleNormalizer/ShorthandsNormalizerFactory'; | ||
|
||
describe('StyleNormalizer', () => { | ||
describe('shorthand normalizers creation', () => { | ||
it('creates proper sides normalizers', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [SIDES]); | ||
|
||
assert.isOk(styleNormalizer.normalizers.test, 'normalizer not created'); | ||
}); | ||
it('creates proper horizontal normalizers', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [HORIZONTAL]); | ||
|
||
assert.isOk(styleNormalizer.normalizers.testHorizontal, 'normalizer not created'); | ||
}); | ||
it('creates proper vertical normalizers', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [VERTICAL]); | ||
|
||
assert.isOk(styleNormalizer.normalizers.testVertical, 'normalizer not created'); | ||
}); | ||
it('creates proper horizontal normalizers', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [CORNERS]); | ||
|
||
assert.isOk(styleNormalizer.normalizers.test, 'normalizer not created'); | ||
}); | ||
it('creates multiple normalizers', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [SIDES, HORIZONTAL, VERTICAL]); | ||
|
||
assert.isOk(styleNormalizer.normalizers.test, 'normalizer not created'); | ||
assert.isOk(styleNormalizer.normalizers.testHorizontal, 'normalizer not created'); | ||
assert.isOk(styleNormalizer.normalizers.testVertical, 'normalizer not created'); | ||
}); | ||
it('throws error if normalizer for shorthand already exists', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
assert.throws(() => { | ||
styleNormalizer.createNormalizers('test', [SIDES, CORNERS]); | ||
}, 'Normalizer for \'test\' shorthand already exists'); | ||
}); | ||
}); | ||
describe('normalizers creation with suffix', () => { | ||
it('creates proper normalizers with suffix', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [SIDES], 'Suffix'); | ||
|
||
assert.isOk(styleNormalizer.normalizers.testSuffix, 'normalizer not created'); | ||
}); | ||
it('creates proper normalizers with suffix', () => { | ||
const styleNormalizer = new StyleNormalizer(); | ||
styleNormalizer.createNormalizers('test', [SIDES, VERTICAL], 'Suffix'); | ||
|
||
assert.isOk(styleNormalizer.normalizers.testSuffix, 'normalizer not created'); | ||
assert.isOk(styleNormalizer.normalizers.testVerticalSuffix, 'normalizer not created'); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import React from 'react-native'; | ||
import { assert } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Theme } from '../'; | ||
import StyleProviderTestAppComponent from './mocks/StyleProviderTestAppComponent'; | ||
import StyleProviderTestComponent from './mocks/StyleProviderTestComponent'; | ||
|
||
describe('StyleProvider', () => { | ||
it('provides a theme', () => { | ||
const demo = mount( | ||
<StyleProviderTestAppComponent> | ||
<StyleProviderTestComponent /> | ||
</StyleProviderTestAppComponent> | ||
); | ||
const passedTheme = demo.find(StyleProviderTestComponent).nodes[0].getThemeStyle(); | ||
|
||
assert.isTrue(passedTheme instanceof Theme, 'theme not available in context'); | ||
}); | ||
}); |
Oops, something went wrong.