0
import React from 'react';
import {
    StyleSheet,
    Text,
    View,
    ScrollView,
} from 'react-native';

import { Content, Card, CardItem, Body, Icon, Image, Right, Left, Thumbnail, Button } from 'native-base';
import  HTMLView from 'react-native-htmlview'

import styles from '../components/CustomStyles'
import htmlstyles from '../styles/htmlstyles'

import TimeAgo from 'react-native-timeago'


export default class QuestionsData extends React.Component
{
    constructor(props)
    {
        super(props);
        this.state =
            {
                navigation: null
            }
    }

    componentDidMount()
    {
        this.state.navigation = this.props.navigation;
    }

    viewExtraFile = () =>{
        this.props.navigation.navigate("ExtraFile");
    };

    render() {

        let questions = this.props.data.map(function (questionData, index)
        {
            let  extra_file = "";
            if(questionData.extra_file_details.file_name !== undefined)
            {
                extra_file = (<CardItem>
                    <Button transparent onPress={()=> this.viewExtraFile()}> <Text style={styles.linkText}>{questionData.extra_file_details.file_name} </Text></Button>
                </CardItem>);
            }
            return (
                <Card transparent style={styles.card}>
                    <CardItem>
                        <Left>
                            <Thumbnail source={{uri: questionData.poster_image_url}} />
                            <Body>
                            <Text style={styles.username}>{questionData.poster_name}</Text>
                            <Text note style={styles.category}>{questionData.section_name}</Text>

                            </Body>
                        </Left>
                    </CardItem>
                    <CardItem content>
                        <HTMLView stylesheet={htmlstyles}
                            value={questionData.question }/>
                    </CardItem>
                    {extra_file}
                    <CardItem>
                        <Left>
                            <Button transparent>
                                <Icon name="thumbs-up" />
                                <Text>{questionData.num_applause} Applause</Text>
                            </Button>
                        </Left>
                        <Body>
                        <Button transparent>
                            <Icon  name="chatbubbles" />
                            <Text>{questionData.num_answers} Answers</Text>
                        </Button>
                        </Body>
                        <Right>
                            <Button transparent>
                                <Icon name='time'/>
                                <Text><TimeAgo time={questionData.time}/></Text>
                            </Button>

                        </Right>
                    </CardItem>
                </Card>
            )
        });
        return (

            <Content>
                {questions}
            </Content>
        );
    }


}

I can not access viewExtraFile method, someone please help on how i can do it

2 Answers 2

1

Change

this.props.data.map(function (questionData, index)
{

to

this.props.data.map((questionData, index) => {

Otherwise this inside of the map will not refer to this outside of the map.

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

1 Comment

It does not work it i get an error saying { expected. I am using webstorm
0

After some iterative work I did this and it worked

export default class QuestionsData extends React.Component

{ constructor(props) { super(props); this.state = { navigation: null } }

componentDidMount()
{
    this.state.navigation = this.props.navigation;
}

questionList(props)
{
    return props.data.map(function (questionData, index)
    {
        let  extra_file = "";
        if(questionData.extra_file_details.file_name !== undefined)
        {
            extra_file = (<CardItem>
                <Button transparent onPress={()=> props.navigation.navigate("ExtraFile")}> <Text style={styles.linkText}>{questionData.extra_file_details.file_name} </Text></Button>
            </CardItem>);
        }
        return (
            <Card transparent style={styles.card}>
                <CardItem>
                    <Left>
                        <Thumbnail source={{uri: questionData.poster_image_url}} />
                        <Body>
                        <Text style={styles.username}>{questionData.poster_name}</Text>
                        <Text note style={styles.category}>{questionData.section_name}</Text>

                        </Body>
                    </Left>
                </CardItem>
                <CardItem content>
                    <HTMLView stylesheet={htmlstyles}
                              value={questionData.question }/>
                </CardItem>
                {extra_file}
                <CardItem>
                    <Left>
                        <Button transparent>
                            <Icon name="thumbs-up" />
                            <Text>{questionData.num_applause} Applause</Text>
                        </Button>
                    </Left>
                    <Body>
                    <Button transparent>
                        <Icon  name="chatbubbles" />
                        <Text>{questionData.num_answers} Answers</Text>
                    </Button>
                    </Body>
                    <Right>
                        <Button transparent>
                            <Icon name='time'/>
                            <Text><TimeAgo time={questionData.time}/></Text>
                        </Button>

                    </Right>
                </CardItem>
            </Card>
        )
    });
}

render() {
    return (

        <Content>
            {this.questionList(this.props)}
        </Content>
    );
}

}

I created a function that displays the list

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.