Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Override Default Indicator Styles #13

Closed
yyalim opened this issue Nov 23, 2015 · 9 comments
Closed

How to Override Default Indicator Styles #13

yyalim opened this issue Nov 23, 2015 · 9 comments

Comments

@yyalim
Copy link

yyalim commented Nov 23, 2015

I want to move dots upper and make them bigger. I can do it by editing, DefaultViewPageIndicator.js file under the node modules but i know it is not right way. Is there better solution for this?

@race604
Copy link
Owner

race604 commented Nov 24, 2015

You can implement your own indicator similar DefaultViewPageIndicator, and set the renderPageIndicator prop of ViewPager to use it.

@yyalim
Copy link
Author

yyalim commented Nov 24, 2015

I tried what you say like this;

first copied DefaultViewPageIndicator to my project folders, then code like this...

import ViewPager from 'react-native-viewpager';
import ViewPageIndicator from './Helpers/ViewPageIndicator';

// ...

class Welcome extends React.Component {
// ...
    render() {
        return (
            <ViewPager
                style={styles.ViewPager}
                dataSource={this.state.dataSource}
                renderPage={this._renderPage}
                isLoop={false}
                autoPlay={false}
                renderPageIndicator={ViewPageIndicator}
            />
        );
    }
// ...
}

// etc...

But i got error that says;

Error: Can't add property props, object is not extensible
 stack: 
  Object.Constructor [as renderPageIndicator]                                  index.ios.bundle?…:22611
  React.createClass.renderPageIndicator                                        index.ios.bundle?…:54147
  React.createClass.render                                                     index.ios.bundle?…:54241
  ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext  index.ios.bundle?…:11718
  ReactCompositeComponentMixin._renderValidatedComponent                       index.ios.bundle?…:11740
  wrapper [as _renderValidatedComponent]                                       index.ios.bundle?…:2740
  ReactCompositeComponentMixin.mountComponent                                  index.ios.bundle?…:11237
  wrapper [as mountComponent]                                                  index.ios.bundle?…:2740
  Object.ReactReconciler.mountComponent                                        index.ios.bundle?…:3945
  ReactCompositeComponentMixin.mountComponent                                  index.ios.bundle?…:11243
 URL: undefined
 line: undefined
 message: Can't add property props, object is not extensible

Am i doing it wrong?

@race604
Copy link
Owner

race604 commented Nov 25, 2015

The renderPageIndicator prop should be a function. In your case, you should use like this:

class Welcome extends React.Component {
    renderIndicator() {
        return <ViewPageIndicator />
    },
    render() {
        return (
            <ViewPager
                style={styles.ViewPager}
                dataSource={this.state.dataSource}
                renderPage={this._renderPage}
                isLoop={false}
                autoPlay={false}
                renderPageIndicator={this.renderIndicator}
            />
        );
    }
// ...
}

@yyalim
Copy link
Author

yyalim commented Nov 25, 2015

Thank you. This solved my problem.

You should document this, otherwise people like me will never know how to do that.

@amibition521
Copy link

I met the same problem with you, could you let me have a look viewpagerindicator code?

@yyalim
Copy link
Author

yyalim commented Dec 17, 2015

I used default indicator, just edited style. It is here on repo.

@amibition521
Copy link

you edit style? which style? Is viewpager style?

@amibition521
Copy link

Thanks !!! I solve the question.Thank you answer my question.This is the first I use github.
var styles = StyleSheet.create({
indicators: {
flex: 1,
alignItems: 'center',
position: 'absolute',
top:180,
//bottom: 10,
left: 0,
right: 0,
backgroundColor: 'transparent',
},
});

@yyalim
Copy link
Author

yyalim commented Dec 17, 2015

No problem, have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants