Multi-platform Kotlin library for parsing and displaying Typeform questionnaires.
If you're just getting started with Typeform, be sure to check out the Developer Platform Documentation.
This library is distributed using JitPack. Add it to your project via gradle:
// Project Level - preferring `build.gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
// Project Level - preferring `settings.gradle`
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
// App/Module Gradle
dependencies {
implementation 'com.github.Nice-Healthcare:typeform-kotlin:0.1.0'
}
This library contains multiple platform packages which comprise a complete toolset for decoding, logic parsing, and display of Typeform questionnaires.
This module contains the Typeform schema and additional models for navigating the logic and completion of a form. Start with the Form
structure, which is the entity retrieved from the Typeform API.
Forms contain Field
s and Logic
which act up the fields. Given a particular Position
- the screen presented or question being asked - and Responses
- answers given to previous questions - the next position can be determined.
val form = Form()
val position = Position.screen(form.firstScreen!!)
val responses: Map<Reference, ResponseValue> = mutableMapOf()
val nextPosition = form.nextPosition(from = position, responses = responses)
The Android source set is a Jetpack Compose implementation used to display and navigate through a Typeform questionnaire. It is designed to be self-contained and customizable to fit in with your apps design.
The FormView
navigation graph is initialized with a Form
and a Conclusion
function/lambda callback. In most cases, the conclusion will include the responses given by the individual questioned. (The only instance where they are not provided is the canceled
case.)
@Composable
fun MyNavGraph(form: Form) {
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = "typeform-form",
) {
composable(route = "typeform-form") {
FormView(
form = form,
conclusion = {
// handle conclusion
},
)
}
}
}
Note, this library is incomplete; not every question type or condition has been implemented. Want to help fix a bug or make improvements? Consider becoming a contributor!
All of the structural components are supported: Welcome Screen, Ending, Statement, and Question Group. Learn more about Typeform Question Types. The currently supported types are:
- Date
- Short Text
- Long Text
- Number
- Rating
- Multiple Choice
- Yes/No
- Dropdown
- Opinion Scale
Every app is unique, so the ability to customize the look and feel of the questions presentation was built in to the library from the start.
The Settings
structure allows for the customization of several aspects of the libraries interface presentation & localization.
Most other aspects use MaterialTheme
to customize the appearance.
- Title style (
Screen.title
,Field.title
)textStyle
:MaterialTheme.typography.h5
- Subtitle style (Applied to navigational buttons)
textStyle
:MaterialTheme.typography.subtitle1
- Body style (Applied to any other text element.)
textStyle
:MaterialTheme.typography.body1
- Prompt style (Applied to supplemental text blocks, like Date toggle.)
textStyle
:MaterialTheme.typography.body2
- Caption style (
Field.properties.description
)textStyle
:MaterialTheme.typography.caption
The 'Exit' confirmation dialog by default uses the subtitle1
and body1
styles for the title & text.
The dialog buttons use style body1
but have color overrides applied:
- Cancel (return to form):
MaterialTheme.colors.primary
- Exit (leave form):
MaterialTheme.colors.error
A form can further be customized by providing an optional header. This is a completely custom view that will be displayed along with each field (question).