BlueBase
  • 💧Introduction
  • Tutorial
    • 1. Getting Started
      • 1.1 Setup
      • 1.2 Add Plugins
      • 1.3 Create Custom Plugin
    • 2. Backend API
      • 2.1 Create Backend API
      • 2.2 Setup Apollo Client
      • 2.3 Generate Typescript Interfaces
    • 3. Create Screens
      • 3.1 Pending Tasks Screen
      • 3.2 Edit Task Screen
      • 3.3 Task Create Screen
      • 3.4 Tab Navigation
    • 4. CRUD Operations
      • 4.1 Creating Tasks
      • 4.2 Reading Tasks
      • 4.3 Updating Tasks
      • 4.4 Deleting Tasks
    • 5. Enhancements
      • 5.1 Internationalisation
      • 5.2 Theming
      • 5.3 Dynamic Images
      • 5.4 Settings & Configurations
      • User Management
  • Key Concepts
    • 🎡Lifecycle Events
    • â›Šī¸Main App Layout
    • 🔌Plugins
      • Plugin API
      • Register a Plugin
      • Making a Plugin Configurable
      • Developing an Analytics Plugin
      • Developing a Logger Plugin
      • Developing a Theme Plugin
    • 🚇Filters
    • 🎁Components
      • Components API
      • Registering a Component
      • Accessing Components
      • Higher Order Components
    • 🎨Themes
      • Consuming Selected Theme
      • Customise Themes
      • Customise Components
      • Theme Configs
      • Theme Structure
    • đŸŽ›ī¸Configs
  • API
    • 📈Analytics
    • 📔Logger
    • đŸ“ĻBlueBase Modules
    • Registry
  • Guides
    • âœ‚ī¸Code Splitting
    • đŸ‘ŊMigrating to V8
  • Components
    • ActivityIndicator
    • BlueBase
      • BlueBaseApp 📌
      • BlueBaseConsumer 📌
      • BlueBaseFilter 📌
      • ThemeConsumer 📌
    • Button
    • ComponentState 📌
    • EmptyState 📌
    • ErrorState 📌
    • Icons
      • Icon
      • DynamicIcon 📌
      • PluginIcon 📌
    • JsonSchema 📌
    • LoadingState 📌
    • Noop 📌
    • Observers
      • DataObserver 📌
      • ErrorObserver 📌
      • HoverObserver 📌
      • WaitObserver 📌
    • StatefulComponent 📌
    • Typography
    • View
Powered by GitBook
On this page
  • Step 1: Download Image
  • Step 2: Add the Image to the Plugin
  • Step 3: Use the Image in the Component
  • Step 4: Use a Different Image for Dark Mode

Was this helpful?

Export as PDF
  1. Tutorial
  2. 5. Enhancements

5.3 Dynamic Images

Previous5.2 ThemingNext5.4 Settings & Configurations

Last updated 3 years ago

Was this helpful?

Let's make our app a bit visually pleasing by adding some images. The perfect place to do this is in the TaskListEmptyState component.

Step 1: Download Image

Download the following image and put it at ssets/no-tasks-light.png.

Step 2: Add the Image to the Plugin

Modify your plugin to add an assets property like the in the code below:

src/index.ts
import { createPlugin } from '@bluebase/core';

import { ToDoAppIcon } from './components/ToDoAppIcon';
import { filters } from './filters';
import { lang } from './lang';
import { routes } from './routes';
import { screens } from './screens';

export default createPlugin({
	key: 'tasks',
	name: 'Tasks',
	description: 'A todo app made with BlueBase framework.',

	assets: {
		NoTasks: require('../assets/no-tasks-light.png'),
	},

	// ... Other properties
});

Basically, we're telling BlueBase that the said image has an ID NoTasks and where to find it. Now we can just reference this image by this ID and BlueBase will take care of loading and rendering it across formats.

Step 3: Use the Image in the Component

Modify the ComponentState node in the TaskListEmptyState component and add a prop imageSource="NoTasks" as shown in the code below:

src/components/TaskListEmptyState/TaskListEmptyState.tsx
<ComponentState
    imageSource="NoTasks"
    title={__('No tasks')}
    imageProps={{ resizeMode: 'contain' }}
    description={__('Start by creating a new task')}
    actionTitle={__('Create Task')}
    actionOnPress={goToCreate}
    actionProps={{ size: 'small', color: 'success', variant: 'outlined' }}
    {...props}
/>

Now when you refresh the app, you should see an image in the empty state.

Step 4: Use a Different Image for Dark Mode

Sometimes we need a different variant of an image for dark mode. Don't worry, we have got you covered here as well.

Download the following image and put it at: assets/no-tasks-dark.png.

Now, modify the assets property in the plugin to match the following:

assets: {
    NoTasks_dark: require('../assets/no-tasks-dark.png'),
    NoTasks_light: require('../assets/no-tasks-light.png'),
},

Try refreshing your app. You'll see different images will be rendered in light mode and dark mode.

Basically, you can define a different image with the same ID (NoTasks in this example) for all of the following scenarios:

Key
Use Case

NoTasks

Default version

NoTasks_dark

Dark mode version

NoTasks_light

Light mode verion

NoTasks_desktop

Desktop Screen Size version

NoTasks_mobile

Mobile Screen Size version

NoTasks_desktop_dark

Desktop Screen Size version on Dark mode

NoTasks_mobile_dark

Mobile Screen Size version on Dark mode

NoTasks_desktop_light

Desktop Screen Size version on Light mode

NoTasks_mobile_light

Mobile Screen Size version on Light mode

Light Mode
Light Mode
Dark Mode
Dark Mode