We will learn concepts of BlueBase by creating a production-ready To-Do app.
We will use Expo CLI to create a new project and add BlueBase to it. If Expo CLI is not installed, go to the Expo CLI Installation guide before proceeding.
Initialize an expo app by executing the following commands:
More info here.
This will open the expo console.
You can launch the web or native version of the app from here.
All functionality in BlueBase is added via plugins. Let us add some ready-made plugins to our project to take a head start on building our app.
Start by adding following devDependencies:
Some of the plugins (react-navigation) require some more dependencies to be installed:
Now in the root folder create the following file plugins.ts
:
The file above exports an array of plugins, imported from their respective modules.
Create another file similar to the one above and name it plugins.native.ts
. This way react-native compiler will load this version rather than plugins.ts
on native platforms.
So by doing this, we can add web-specific plugins in plugins.ts
and native specific code in plugins.native.ts
.
In this case, the difference in the above 2 files is that plugins.ts
uses:
@bluebase/plugin-react-router
@bluebase/plugin-material-ui
While plugins.native.ts
uses the following instead:
@bluebase/plugin-react-navigation
@bluebase/plugin-react-native-paper
Now edit the App.tsx
file and add the following content.
Here, we import the plugins array and pass them to the BlueBaseApp
component as a prop.
Lastly, modify the contents of babel.config.js
file to:
Now run the app again:
You should see the following screen on launch:
So as you can see, by just installing a few plugins, we were able to add a lot of functionality in a very short span of time, by writing very few lines of code.
I'll try to briefly describe what purpose each plugin serves.
@bluebase/plugin-launcher
Adds Android-like "launcher" home screen, that shows app icons.
@bluebase/plugin-settings-app
Adds the Settings section to the app. If you remove this plugin, the settings icon on the home screen will disappear.
@bluebase/plugin-json-schema-components
Provides components that help us build layouts by writing JSON. This is used by the settings plugin.
@bluebase/plugin-material-ui
@bluebase/plugin-react-router
@bluebase/plugin-react-native-paper
@bluebase/plugin-react-navigation
@bluebase/plugin-responsive-grid
Provides Grid components (Column, Row, etc). Used by Launcher plugin.
@bluebase/plugin-vector-icons
By now it should be clear that all functionality in BlueBase is added via plugins. So in order to add views to our To-Do app, we need to create our own plugin.
Start by adding the following dependency:
This library provides typescript typings of components imported from the BlueBase context.
The first thing that we will do is to create a plugin icon component. Create the following files:
Time to create the plugin itself. Create the following file:
In the above code, we use the createPlugin
function from the the @bluebase/core
library. This function takes attributes as input, and returns a BlueBase Plugin.
The key
property servers as the plugin ID, as well as the slug in the plugin URL path. So in this case the path to access this plugin would be: http://localhost:19006/p/tasks
.
The name
and description
properties are pretty self explanatory. The name
property is rendered below the icon on the home screen.
The icon
property defines the plugin icon that is rendered on the home page. In the icon.component
sub-property tells which component to render.
We use 'ToDoAppIcon'
value, which is the same as the key on the component object in Line 10. So, by doing this we are telling BlueBase to render a component by the key ToDoAppIcon
.
Lastly, the indexRoute
key tells BlueBase which screen to navigate to when the icon is pressed. We tell it to go to HomeScreen
here. Since we would already be on the HomeScreen
so pressing this button will not do anything.
Now we're all set to use our shiny new plugin Edit our plugin files to add our own plugin to the list.
Now run the app again:
You should see the following screen on launch:
Provides Material UI components on the web. Uses the library.
Provides Navigation capability on the web. Uses the library.
Provides Material UI components on native. Uses the library.
Provides Navigation capability on native. Uses the library.
Provides SVG vector icons used on various screens, as shown above. Uses the library.
The code above uses the BlueBase theme syntax to customize styles. Read more about it in the .
The components
property is a Map of key, value pair. Where key is a string, and value is a React component. This map is used by BlueBase to store these components in its context. These can be fetched dynamically at a later stage, and can be overwritten by plugins to change the plugin implementation. More on this .
We save the ToDoAppIcon
component in the example above.