React-native-image-viewer: RenderIndicator as shown example returning error

Created on 30 Sep 2019  路  2Comments  路  Source: ascoders/react-native-image-viewer

I tried this:

              <ImageViewer
                    renderIndicator={(currentIndex, allSize) => currentIndex + "-" + allSize}
                    imageUrls={ALI.getAuctionMainImages()}
                    style={styles.auctionImageViewerPortrait}
                    onChange={(index) => this.onMove(index)}
                    index={this.state.imageViewerIndex}
                    backgroundColor={"white"} // TODO Link background color to styles
                />

and this line keeps giving me an error:
renderIndicator={(currentIndex, allSize) => currentIndex + "-" + allSize}

The error is: Invariant Violation: Text strings must be rendered within a component.

Most helpful comment

@MrEdinLaw - I just had a similar issue. But then I applied zIndex style to my indicator component.
I believe when you pass your custom component - you need to handle the zIndex of it aswell.
Ex -

renderIndicator = {
  (currentIndex, allSize) => {
    return (
             <View style={{position: "absolute", zIndex: 9999}}>
               <Text style={{fontSize: 50, color: "#000"}}>{currentIndex} / {allSize}</Text>
             </View>);
    }
}

All 2 comments

I tried it now with this line:

renderIndicator={(currentIndex, allSize) => <Text>{currentIndex} / {allSize}</Text>}

I don't get the error anymore but it does not render/show.

@MrEdinLaw - I just had a similar issue. But then I applied zIndex style to my indicator component.
I believe when you pass your custom component - you need to handle the zIndex of it aswell.
Ex -

renderIndicator = {
  (currentIndex, allSize) => {
    return (
             <View style={{position: "absolute", zIndex: 9999}}>
               <Text style={{fontSize: 50, color: "#000"}}>{currentIndex} / {allSize}</Text>
             </View>);
    }
}
Was this page helpful?
0 / 5 - 0 ratings