npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@app-masters/questions-component

v1.0.2

Published

A component for question and andswers management for React Native

Downloads

12

Readme

Questions component is a component used to make forms in a QnA style. It receives the views that will be used to render questions and also for each one of answer type. It also receives the data, which is the Json/Object used to render questions and answers.

Installing

You only need to run:

npm i @app-masters/questions-component --save

Usage

Before using the component, follow the installation and usage steps of each dependecy(look down) first.

The starting point component is the QuestionAnswers component, you just got to import it, and call it giving the views you want to use.

You have to give it the custom views you want it to render. But it already comes with some default views that you can use and also help you implement your own.

Like this:

import React from 'react';
import {
	QuestionAnswers,
	QuestionView,
	AnswerCheckView,
	AnswerTextView,
	AnswerPhotoView
} from '@app-masters/questions-component';

class Example extends React.Component {
	constructor(props) {
		super(props);
		this.onFormSubmit = this.onFormSubmit.bind(this);
	}
	render() {
		return <QuestionAnswers
			componentDefinition={{
				questionView: QuestionView,
				answerCheckView: AnswerCheckView,
				answerTextView: AnswerTextView,
				answerPhotoView: AnswerPhotoView,
			}}
			data={this.props.data}
			onFormSubmit={this.onFormSubmit} />;
	}

	onFormSubmit(answers) {
		console.log(answers);
	}
}

export default Example;

Metadata

As you can see on the example above, we are giving the component some data that for this example comes from this.props.data. An example of this data is at the bottom of the page.

This metadata can be anything, but must follow the pattern:

Category -  
    Id: Int  
    Content: String  
    Questions: Question[]  

Question -  
    Id: Int  
    Type: "multiple", "single", "text"  
    Content: String  
    Answers: Answer[]  
    ShouldDisplay: ShouldDisplay[]  

ShouldDisplay -  
    AnswerId: Int  
    QuestionId: Int

Answer -
    Id: Int  
    Type: "check", "input", "photo"
    Content: String  

Any question can depend on any previous answer using the "ShouldDisplay" property, but it is important to know that, this dependent question must be placed on the array just after the last question it depends from.

Definitions

These are the component properties, and all of them are required:

    componentDefinition: {
        QuestionView, // This is the view that will be used to display a single question, this view shows the question title and the answer array
        AnswerCheckView, // This is the corresponding view for an answer of type "check"
        AnswerTextView, // This is the corresponding view for an answer of type "text"
        AnswerPhotoView, // This is the corresponding view for an answer of type "photo"
    },
    data: {}, // This is the data used to render the question tree
    onFormSubmit: (answers) => void // This is the callback that is called when the last question is answered

Dependencies

  • ivpusic/react-native-image-crop-picker: The component depend on this package to cut images on answers of type "photo"
    !Tip: If after installing this package, you get the error: Could not find method METHOD_NAME for arguments, try removing the line vectorDrawables.useSupportLibrary on your ./android/app/build.gradle.

  • beefe/react-native-actionsheet: The component depend on this package so the action sheet that allows the user to select photo or gallery to shown.

  • app-masters/react-native-ui-kit: The component uses this ui kit for some of its styling.

Before using the component, follow the installation and usage steps of each dependecy first.

Known errors

  • If you get the error TypeError: Cannot read property 'ph3' of null:
    You are not calling startStyles(AppStyles) from the app-masters/react-native-ui-kit dependecy. Check this dependecy installation instructions.

Data example

This is an example of the metadata Json:

{
    "data": {
        "categories": [
            {
                "categoryId": 1,
                "content": "Indicadores Nutricionais",
                "questions": [
                    {
                        "questionId": 1,
                        "type": "multiple",
                        "content": "Qual é a classificação da condição corporal do animal?",
                        "answers": [
                            {
                                "answerId": 1,
                                "type": "check",
                                "content": "Muito magro"
                            },
                            {
                                "answerId": 2,
                                "type": "check",
                                "content": "Magro"
                            },
                            {
                                "answerId": 3,
                                "type": "check",
                                "content": "Ideal"
                            },
                            {
                                "answerId": 4,
                                "type": "check",
                                "content": "Acima do peso"
                            },
                            {
                                "answerId": 5,
                                "type": "photo",
                                "content": "Tire uma foto"
                            }
                        ]
                    },
                    {
                        "questionId": 2,
                        "type": "text",
                        "content": "Qual seria o grau de mau trato?",
                        "answers": [
                            {
                                "answerId": 6,
                                "type": "text",
                                "content": "Descreva"
                            }
                        ]
                    },
                    {
                        "questionId": 3,
                        "type": "single",
                        "content": "O animal possui alimentação disponível?",
                        "answers": [
                            {
                                "answerId": 7,
                                "type": "check",
                                "content": "Sim"
                            },
                            {
                                "answerId": 8,
                                "type": "check",
                                "content": "Não"
                            }
                        ]
                    },
                    {
                        "questionId": 4,
                        "type": "single",
                        "content": "O que o animal come?",
                        "answers": [
                            {
                                "answerId": 9,
                                "type": "check",
                                "content": "Ração"
                            },
                            {
                                "answerId": 10,
                                "type": "check",
                                "content": "Comida caseira"
                            },
                            {
                                "answerId": 11,
                                "type": "text",
                                "content": "Outros"
                            }
                        ],
                        "shouldDisplay": [
                            {
                                "questionId": 3,
                                "answerId": 7
                            }
                        ]
                    }
                ]
            }
        ]
    }
}