@joyfill/components-react-native
v1.0.0
Published
Joyfill React Native Components
Readme
@joyfill/components-react-native
We recommend visiting our official react-native setup guide https://docs.joyfill.io/docs/react-native.
Project Requirements
- React 19
- React Native 0.86.x with the New Architecture enabled
- Expo SDK 57 (Expo applications only)
- Node 22.13+ within Node 22, or Node 24.3+
Install Dependency
Keep your existing dependencies when they satisfy the SDK's peer dependency ranges and your application's framework requirements. Install only missing packages, and change existing versions only to resolve a compatibility conflict. All required native peers must be present, even if your forms use only a subset of field types.
Before installing, compare your app's installed versions with the release's declared ranges:
npm view @joyfill/[email protected] peerDependencies
npm ls react react-native react-native-webview react-native-svg \
@react-native-community/datetimepicker react-native-gesture-handler \
react-native-reanimated react-native-workletsRun installation commands in your application directory and keep using your existing package manager and lockfile. A version outside the declared ranges needs a compatibility review; the ranges alone do not establish that a full application migration is necessary.
React-Native CLI (bare)
Keep your existing React and React Native versions if they satisfy the declared ranges. If a framework upgrade is needed, follow the React Native upgrade guide to update the native project as well.
npm
npm install @joyfill/[email protected]Yarn
yarn add @joyfill/[email protected]If native peers are missing, add them using the ranges below. Remove packages you already have at compatible versions from this command. For Yarn, replace npm install with yarn add.
npm install "react-native-webview@>=13.16.1 <14" \
"react-native-svg@>=15.15.4 <16" \
"@react-native-community/datetimepicker@>=9.1.0 <10" \
"react-native-gesture-handler@>=2.32.0 <3" \
"react-native-reanimated@>=4.5.1 <4.6" "[email protected]"Reanimated, Worklets, and React Native must also support each other. Check the Reanimated compatibility table when changing one of these packages.
If not already configured, add the Worklets plugin last in babel.config.js, retaining other plugins before it:
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: ['react-native-worklets/plugin'],
};Remove an old react-native-reanimated/plugin entry if you are upgrading from Reanimated 3. Do not configure both plugins.
If you add or change native dependencies, update iOS pods and rebuild using your application's usual workflow.
Expo (managed)
Keep your existing Expo configuration when its React, React Native, and native dependency versions satisfy Joyfill's declared ranges. Expo SDK 57 is the tested framework target for this release. If your current SDK cannot provide a compatible set, review Expo's SDK upgrade guide before changing framework versions.
Install Joyfill:
npx expo install @joyfill/[email protected]For missing native peers, let Expo select versions for your current Expo SDK. Remove packages you already have at compatible versions from this command, then confirm the selected versions also satisfy Joyfill's ranges:
npx expo install react-native-webview react-native-svg \
@react-native-community/datetimepicker react-native-gesture-handler \
react-native-reanimated react-native-workletsUse npx expo install --check to review framework compatibility; it may prompt to update mismatched packages. Expo's version selection does not replace checking Joyfill's peer requirements. See Expo's dependency validation guidance.
Implement your code
Below is a usable example of our react-native document native embedded.
import React, { useState, useEffect } from 'react';
import { Dimensions, View } from 'react-native';
import { JoyDoc, getDefaultDocument } from '@joyfill/components-react-native';
const screenWidth = Dimensions.get('window').width;
const template = <PASTE_JSON_TEMPLATE>
function Document() {
const [doc, setDoc] = useState(template || getDefaultDocument());
return (
<View style={{flex: 1}}>
<JoyDoc
mode="fill"
doc={doc}
width={screenWidth}
onChange={(changelogs, doc) => {
console.log('onChange doc: ', doc);
setDoc(doc);
}}
onUploadAsync={async (params) => {
// Add your picker/upload handler and return { url, fileName, filePath } objects.
console.log('onUploadAsync: ', params);
return []; // No file selected; leave the document unchanged.
}}
/>
</View>
);
}
export default Document;
JoyDoc Params
mode: 'fill' | 'readonly'- Required*
- Enables and disables certain JoyDoc functionality and features.
- Options
fillis the mode where you simply input the field data into the formreadonlyis the mode where everything in the form is set to read-only.
doc: object- The JoyDoc JSON object to load into the SDK. Must be in the JoyDoc JSON data structure.
- The SDK uses object reference equality checks to determine if the
docor any of its internalpagesorfieldshave changed in the JSON. Ensure you’re creating new object instances when updating the document, pages, or fields before passing the updateddocJSON back to the SDK. This will ensure your changes are properly detected and reflected in the SDK.
initialPageId: string- Specify the initial page to display in the form.
- Utilize the
_idproperty of a Page object. For instance,page._id. - If page is not found within the
docit will fallback to displaying the first page in thepagesarray.
view: 'mobile' | 'desktop'- Enables you to set the active view. Defaults to mobile. Only PDF deskop page view are supported right now. If the active page does not have a PDF view then it will default back to using the mobile view.
navigation: object- Display/hide page and view navigation.
- Defaults to
{ pages: true } - Set the
pagesproperty to true (display) or false (hide). For instance,{pages: false}hides the page navigation. - Set the
viewsproperty to true (display) or false (hide). For instance,{views: false}hides the views (mobile and primary) navigation options.
onChange: (changelogs: object_array, doc: object) => {}- Used to listen to any field change events.
changelogs: object_array- Can contain one ore more of the changelog object types supported. Learn more about changelogs
doc: object- Fully updated JoyDoc JSON structure with changes applied.
onFocus: (params: object, e: object) => {}- Used to listen to field focus events.
params: object- Specifies information about the focused field.
e: object- Element helper methods.
blur: Function- Triggers the field blur event for the focused field.
- If there are pending changes in the field that have not triggered the
onChangeevent yet then thee.blur()function will trigger both the change and blur events in the following order: 1)onChange2)onBlur. - If the focused field utilizes a modal for field modification, ie. signature, image, tables, etc. the
e.blur()will close the modal.
onBlur: (params: object) => {}- Used to listen to field focus events.
params: object- Specifies information about the blurred field.
theme: object- Specify custom theme properties.
- Sample theme object
{ fontFamily: { regular: "Ariel", bold: "Ariel-bold" }, button: { primary: { fontWeight: "bold", borderRadius: "10px", ... } } - The button
primary,secondary, anddangersupport the React Native Supported Styles fontFamily: objectfontFamily.regular: stringfontFamily.bold: string- Apply custom font family to display text.
- IMPORTANT: If you're using a custom font, you are responsible to ensure the fonts are loaded before rendering the component. Could result in an error if font is not loaded properly before render.
button: objectbutton.primary: object- Specifies styles for primary field buttons.
button.secondary: object- Specifies styles for secondary internal field buttons.
button.danger: object- Specifies styles for delete buttons.
SDK Helper Methods
getDefaultDocument- Get a default Joyfill Document object
getDefaultTemplate- Get a default Joyfill Template object
getDocumentFromTemplate: ( template: object )- Generate a Joyfill Document object from a Joyfill Template object
duplicate: ( original: object, defaults: object )- Duplicate a Joyfill Document or Template object.
duplicatePage: ( original: object, fileId: string, pageId: string )- Duplicate a Joyfill Document or Template Page object.
- Returns:
{ doc: object, changelogs: array }docfully updated Document or Template with the page addedchangelogsarray of changelogs for new duplicate page.
applyLogic: ( items: object_array, fields: object_array, fieldLookupKey: string )- Apply show/hide logic to pages and fields for external filtering.
- Wrapper around
@joyfill/conditional-logiclibrary. View library
Field Events
- Text, Textarea, Number
onFocus(params: object, e: object)is fired when the field is focused.onChangeis fired when the field value is modified.onBluris fired when the field is blurred.
- Date, Dropdown
onFocusis fired when the field is pressed and selection modal is displayed.onChangeis fired when the field value is modified.onBluris fired when the field is blurred and the selection modal is closed.
- Multiselect
onFocusis fired when an option is selected or unselected for the first time on the field.onChangeis fired when an option is selected or unselected in the field.
- Chart
onFocusis fired when “view” button is pressed and modal is displayed.onChangeis fired when the field value is modified.onBluris fired when modal is closed.
- Image
onFocusis fired when “view” button is pressed and modal is displayed.- An empty image field that is focused will also trigger the
onUploadAsyncrequest. - A populated image field that is focused will trigger the image modal to open.
- An empty image field that is focused will also trigger the
onChangeis fired when the field images are uploaded or removed.onBluris fired when modal is closed.
- Signature
onFocusis fired when open modal button is pressed and modal is displayed.onChangeis fired when the field value is modified.onBluris fired when the modal is closed.
- Table
onFocusis fired when “view” button is pressed and modal is displayed.onBluris fired when modal is closed.- Table Cells
- Text Cell
onFocusis fired when the cell is focused.onChangeis fired when the cell value is modified.onBluris fired when the cell is blurred
- Dropdown Cell
onFocusis fired when the cell is pressed and selection modal is displayed.onChangeis fired when the field value is modified.onBluris fired when the cell is blurred and the selection modal is closed.
- Image Cell
onFocusis fired cell is pressed and modal is displayed.onChangeis fired when the cell images are uploaded or removed.onBluris fired when modal is closed.
- Text Cell
IMPORTANT NOTE: JoyDoc SDK onFocus, onChange and onBlur events are not always called in the same order. Two different fields can be triggering events at the same time. For instance, if you have Field A focused and then focus on Field B, the Field B onFocus event could be fired before the Field A onBlur event. Always check the event params object ids to match up the associated field events.
