Welcome to the Mobiscroll API Reference. You can find the most up to date information about usage and customization options here.
Having trouble? Ask for help.
Getting Started with Mobiscroll for React
Mobiscroll is a collection of UI components that helps deliver great mobile apps, websites with a great user experience and in getting five-star app store reviews. The controls follow platform UX guidelines and can be styled with the Theme Builder for a perfect fit.
What is React?
React is a JavaScript library for building user interfaces. Mobiscroll for React is a collection of React Components that help you use the Mobiscroll Controls in a React application.
More about React...
Using the Mobiscroll CLI and NPM
Step 1: Create an app
If you don't have an app at hand, create a starter with the Create React App (sudo access might be required).
$ npx create-react-app my-app
$ cd my-starter
Step 2: Install the Mobiscroll CLI and configure the app
Install Mobiscroll CLI from NPM (you'll only have to do it once).
$ npm install -g @mobiscroll/cli
On Windows client computers, the execution of PowerShell scripts is disabled by default. When using Powershell, to be able to install the Mobiscroll CLI you will need to set the following execution policy:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Make sure to read the message displayed after executing the command and follow the instructions.
Run mobiscroll config react
in your terminal window.
$ mobiscroll config react
Step 3: Let's see if Mobiscroll was installed correctly
Here is how can the Mobiscroll resources be imported to a React component:
import { Datepicker, Eventcalendar } from "@mobiscroll/react";
import "@mobiscroll/react/dist/css/mobiscroll.min.css";
If the application is configured with the cli's --no-npm
mode, the js import will remain the same, only the css import location needs to be modified to the following:
import "@mobiscroll/react/dist/css/mobiscroll.react.min.css";
To test it let's import the Datepicker component and add it to the App function.
If you just created a new app, you can modify the src/App.js
file.
import React from 'react';
import { Datepicker } from '@mobiscroll/react';
import "@mobiscroll/react/dist/css/mobiscroll.min.css";
export function App() {
const [birthday, setBirthday] = React.useState(null);
const onBirthdayChange = (ev) => {
setBirthday(ev.value);
}
return <Datepicker value={birthday} onChange={onBirthdayChange} label="When were you born?" />
}
To build the app just run the npm start
in the CLI:
$ npm start
Communication with Mobiscroll Components
React's policy to communication between components is also valid when using the Mobiscroll Components: passing props from parent to child and using event handlers.
function YourComponent(props) {
const [selected, setSelected] = useState(null);
const onSelectedChange = (ev) => {
setSelected(ev.value);
};
const [display] = useState('center');
return <Datepicker value={selected} theme="ios" display={display} onChange={onSelectedChange} />
}
function YourComponent(props) {
const options = useMemo(() => {
return {
theme: 'ios',
display: 'center',
};
});
return <Datepicker options={opt} />
}
function YourComponent(props) {
const options = useMemo(() => {
return {
theme: 'ios',
display: 'center',
};
});
return <Datepicker options={opt} theme="my-custom-ios-theme" />
}
In the above example my-custom-ios-theme
takes precedence over the ios
theme since it is passed as an individual attribute
Reaching the mobiscroll instance
Because sometimes it is inevitable to call methods on the mobiscroll instance (ex. open, close, refresh), the mobiscroll instance can be reached, as any other component in react, by using a ref. The instance is also available in Mobiscroll events as the second argument. You can find a more detailed description on reaching the instance in the Instance section of our docs.
Global Settings
With the setOptions
method, you can set global options that are needed across your application or page.
These options will be applied to all components. Including all the components that are initialized after the setOptions call.
Components that were initialized before the setOptions call, will be updated with the new options as well at the time of the setOptions function call.
import { setOptions } from '@mobiscroll/react'
// Apply options globally to all Mobiscroll components
mobiscroll.setOptions({
theme: 'ios',
themeVariant: 'dark'
});
For more examples check out the demo page.
Using Mobiscroll v4 alongside v5
The 5th major version of Mobiscroll contains a limited number of components, compared to v4. If you need to keep using some components from v4, which are not present in the newer version, please follow this guide.