在反应原生iOS应用程序中使用材质设计的最简单方法是什么?

时间:2016-01-04 04:12:42

标签: material-design react-native material-ui

我已经在Github上找到了这些部分实现作为主要竞争者,尽管他们还有很长的路要走:

他们目前缺乏一些我想要使用的组件。我还缺少一种替代解决方案吗?

4 个答案:

答案 0 :(得分:14)

我正在react-native-material-ui工作,应该接近material-ui

我们需要选择完全且非常轻松地更改应用程序的样式/主题。并没有提供这种可能性的库。当然,你可以通过组件的道具设置几件事。但是,您必须在代码中使用该组件的每个位置更改它。

react-native-material-ui

  • 您可以定义将与默认样式合并的对象,并在您的应用中随处使用 - 非常简单
  • 仍有可能通过道具
  • 更改一个组件的样式
  • 或者您甚至可以在自己的组件中使用您的风格(通过上下文)

答案 1 :(得分:10)

我们最近在Callstack发布了React Native Paper:https://callstack.github.io/react-native-paper

一些亮点包括:

  • 遵循最新的材料设计指南
  • Nice iting API,允许您动态切换主题
  • 默认无法访问
  • 支持RTL模式
  • 适用于Android和iOS,包括Expo

还有针对我们的底部导航组件的React Navigation的官方集成。

以下是一些截图:

Button TextInput FAB

不确定您缺少哪些组件。所以不确定这是否满足您的需求。

答案 2 :(得分:8)

我相信xinthink的这个图书馆将实现你所追求的目标。

我在Android和iOS上都使用它。

老实说,所有这些图书馆只能给你一些风格,你也可以写自己。

例如,你可以像这样创建一个材料设计卡:

       <ScrollView style={styles.scrollView}>
          <View style={styles.cardContainer}>
            <View style={styles.card}>
              <View resizeMode="cover" style={styles.cardTitleContainer}>
                <Text style={styles.cardTitle}>Commented on</Text>
              </View>
              <View  // TextView padding not handled well on Android https://github.com/facebook/react-native/issues/3233
                style={{
                  padding : 15,
                }}
                >
                <Text style={styles.cardContent}>
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                  Mauris sagittis pellentesque lacus eleifend lacinia...
                </Text>
              </View>
              <View style={styles.cardAction}>
                <Text>My Action</Text>
              </View>
            </View>
          </View>
        </ScrollView>

使用以下样式:

  cardContainer:{
    flex: 1,
    alignItems: 'stretch',
    backgroundColor: '#F5FCFF',
    padding: 20,
    marginTop: self.props.device.platform === 'android' ? 56 : 0,
  },

  card:{
    flex: 1,
    backgroundColor: '#ffffff',
    borderRadius: 2,
    borderColor: '#ffffff',
    borderWidth: 1,
    shadowColor: 'rgba(0, 0, 0, 0.12)',
    shadowOpacity: 0.8,
    shadowRadius: 2,
    shadowOffset: {
      height: 1,
      width: 2,
    },
  },
  cardTitleContainer:{
    flex: 1,
    height: 170,
  },
  cardTitle:{
    position: 'absolute',
    top: 120,
    left: 26,
    backgroundColor: 'transparent',
    padding: 16,
    fontSize: 24,
    color: '#000000',
    fontWeight: 'bold',
  },

  cardContent:{
    padding:0,
    color: 'rgba(0, 0, 0, 0.54)',
  },

  cardAction:{
    borderStyle: 'solid',
    borderTopColor: 'rgba(0, 0, 0, 0.1)',
    borderTopWidth: 1,
    padding: 15,
  },

我从我在链接中共享的库中获取了此示例代码。您还会注意到此库中没有自定义组件,只是样式。

答案 3 :(得分:2)

我正在使用react-native-material-ui并将其与Redux商店结合使用。 通过这种方式,我可以即时切换主题!

不幸的是,最初我们必须为每个控件定义样式,因为react-native-material-ui的'ThemeProviders uiTheme连接器'似乎是单程票。

无论如何,如果所有内容都已连线,我可以在一个大的styles.js中管理我的所有样式,只包含一个Platform.OS查询,多个外观并通过下拉导致操作/状态更改来更改完整主题,准备好保存在本地持久存储中。

react-native-material-ui看起来很酷。

<ActionButton
              actions={[
                  { icon: 'email', label: 'Email' },
                  { icon: 'phone', label: 'Phone' },
                  { icon: 'sms', label: 'Text' },
                  { icon: 'favorite', label: 'Favorite' },
              ]}
              //not defined
              //hidden={this.state.bottomHidden}
              icon="share"
              transition="speedDial"
              onPress={(action) => {
                  if (myPlatform === 'android') {
                      ToastAndroid.show(action, ToastAndroid.SHORT);
                  }
              } }
              style={{
                  positionContainer: { bottom: 76 },
                  container: myStyle.testBack, //<--DYNAMIC !
              }}
              />
相关问题