Creating Tabs in React Native using TabBarIOS

1.1k views Asked by At

I am new to React and trying to follow this Tutorial.Apparently, It's for an older version of react-native. so Im following and tweaking the code when it's not working. I'm using ReactNative 0.41.

my index.ios.js:

import React, { Component } from 'react';
import {
    AppRegistry,
    TabBarIOS
} from 'react-native';
import Featured from './Featured';
import Search from './Search';

class BookSearch extends Component {

    constructor(props) {
        super(props);
        this.state = {
            selectedTab: 'featured'
        };
    }

    render() {
        return (
            <TabBarIOS selectedTab={this.state.selectedTab}>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'featured'}
                    icon={{uri:'featured'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'featured'
                        });
                    }}>
                    <Featured/>
                </TabBarIOS.Item>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'search'}
                    icon={{uri:'search'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'search'
                        });
                    }}>
                    <Search/>
                </TabBarIOS.Item>
            </TabBarIOS>
        );
    }
}

AppRegistry.registerComponent('BookSearch', () => BookSearch);

and here is the Error:

json value'{uri =featured;}' of type NSMutableDictionary cannot be converted to an image. File not Found

2

There are 2 answers

0
Poorya On BEST ANSWER

As suspected the error was due to syntax change. the new version uses systemIcon='featured' instead of icon={{uri:'featured'}}

2
Codesingh On

I think you are wrong in entering uri of the icon. variable 'featured' is not defined.

I can see there are more errors such as your entry for selectedtab is wrong.

Cheers :)