1

I'm following a tutorial to develop an android app using react native but there're some weird styling issues

  1. Border is not shown
  2. No top padding in first line
  3. The side scroller is centered

Rendered display

this is my code:

import React, { Component } from 'react';
import {
  AppRegistry,
  ListView,
  StyleSheet,
  Text,
  View
} from 'react-native';

class SimpleList extends Component {
    constructor(props) {
        super(props);

        var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        this.state = {
            dataSource: ds.cloneWithRows(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
        };
    }

    _renderRow(rowData) {
        return <Text style={styles.row}>{rowData}</Text>
    }

    render() {
        return (<View style={styles.container}>
            <ListView
                dataSource={this.state.dataSource}
                renderRow={(e) => this._renderRow(e)}/>
        </View>);
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  row: {
    flex: 1,
    fontSize: 24,
    padding: 42,
    borderWidth: 1,
    borderColor: '#DDDDDD'
  }
});

export default SimpleList;

my react native version is 0.30

2 Answers 2

1

I think I've figured it out

  • Top Padding and Border is not working for Text component, it works when I wrapped the Text with View component, and style the wrapper instead
  • Fixed the scroller by using contentContainerStyle instead of style property to define style

don't know why it works in the tutorial though

Sign up to request clarification or add additional context in comments.

Comments

0

for border u can just create function:

border: function(color) {
return {
borderColor: color,
borderWidth: 4
    }
}

you can use like this:

<View style={this.border('green')}>
  1. to adjust height, u can just use, marginTop or marginBottom

  2. you can just use ScrollView like this(make sure import ScrollView)

    <ScrollView>
    <Text style={{fontSize:96}}>Scroll me plz</Text>
    <Image source={require('./img/favicon.png')} />
    </ScrollView>
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.