• Stars
    star
    334
  • Rank 126,264 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Style your React Native components on one place

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

$ npm install --save @shoutem/theme

Docs

All the documentation is available on the Developer portal.

Community

Join our community on Facebook. Also, feel free to ask a question on Stack Overflow using "shoutem" tag.

Examples

Use Shoutem UI, set of components which are made to be customizable by Theme, to see how to work with it.

Create new React Native project:

$ react-native init HelloWorld

Install @shoutem/ui and @shoutem/theme and link them in your project:

$ cd HelloWorld
$ npm install --save @shoutem/ui
$ npm install --save @shoutem/theme
$ rnpm link

Now, simply copy the following to the App.js file of your React Native project:

import React, { Component } from 'react';
import { 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',
    backgroundColor: Colors.BACKGROUND,
  },
};

export default class App 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>
    );
  }
}

Finally, run the app!

$ react-native run-ios

Automated Testing

Jest has been set up to provide the ability to test @shoutem/theme after any changes.

To run tests, first add the following to dependencies in package.json:

  • "react-native": "0.63.2"
  • "react": "16.13.1"
  • "react-dom": "16.13.1"

Or whichever version is relevant after your changes. Then run npm i && npm run test and see if you broke anything.

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:

License

The BSD License Copyright (c) 2016-present, Shoutem

More Repositories

1

ui

Customizable set of components for React Native applications
JavaScript
4,895
star
2

shoutem.github.io

Supercharging React Native development
JavaScript
518
star
3

school

A new React Native app every 2 weeks. With tutorial :)
Objective-C
476
star
4

animation

Animate your React Native components
JavaScript
282
star
5

react-native-shopify

React Native bridge to Shopify Buy SDK
Java
262
star
6

extensions

Shoutem Extensions are common mobile app functionalities that supercharge your React Native development
JavaScript
224
star
7

redux-io

Data fetching with redux made easy
JavaScript
105
star
8

fetch-token-intercept

JavaScript
67
star
9

platform

Shoutem platform
JavaScript
42
star
10

redux-composers

Additional reducer composers besides combineReducers from redux
JavaScript
34
star
11

cli

Shoutem CLI is a tool which helps you build Shoutem extensions faster
JavaScript
31
star
12

UrlBuilder

UrlBuilder is simple and powerful URL builder
C#
11
star
13

cordova-ios-twitter

Twitter plugin for cordova
JavaScript
9
star
14

extension-examples

Examples on extensions
JavaScript
4
star
15

api-sdk

JavaScript
2
star
16

FlurryLib

FlurryLib as uses by ShoutEm
Objective-C
2
star
17

facebook-ios-sdk

Facebook connect SDK with SSO turned off
Objective-C
1
star
18

react-native-calendar-manager

Objective-C
1
star
19

google-admob-ios-sdk

Objective-C
1
star
20

mockup_config

Mockup Config
Python
1
star
21

scriptem-py

A collection of useful shoutem scripts
Python
1
star
22

GTM

GTM as used by ShoutEm
Objective-C
1
star
23

OAuthConsumer

Objective-C
1
star
24

PLCrashReporter

git based checkout of plcrashreporter
Objective-C
1
star
25

ZBar

ShoutEm mirror of ZBar SDK repository
Objective-C
1
star
26

Three20

ShoutEm modification of Three20 library
Objective-C
1
star
27

MoPubSDK

Shoutem modifications to MoPubSDK
Objective-C
1
star
28

string-additions-for-html

As used by ShoutEm
Objective-C
1
star