DEV Community

deepak kumar
deepak kumar

Posted on

Ship mobile apps faster with React-Native-Blossom-UI

React-Native open-source community provides very few UI library which is also great, customizable and up to date. And I faced the same problem and so I decided to make a new one which will be rich in components and also provides a full customizability, that's where the blossom-ui comes in.

You can skip this article and directly run to the Documentation website.

Blossom UI helps you to create an awesome UI on mobile and web platform. It's based on custom design system and it's totally configurable.Main features that it provides -

Base components - This contains all the basic components that react-native provides.
Theme Support - Out of the box Theme support with dark theme.
Customizability - You can customize all the components to match to your UI need.
Icons Support - react-native-vector-icons support out of the box.

Installation

Start with installing the components library.

npm install @react-native-blossom-ui/components
Enter fullscreen mode Exit fullscreen mode

Next install the react-native-vector-icons as it's a peer dependency of the library.

Now wrap your Root Component (Navigation Container) into the BlossomThemeProvider in your App.ts file

import React, { useState } from "react";
import { BlossomThemeProvider } from "@react-native-blossom-ui/components";

import lightTheme from "../lightTheme.json";
import darkTheme from "../darkTheme.json";
import options from "../options.json";
import { MyAppContainer } from "src/navigation";

export default function App() {
  const [isDark, setIsDark] = useState(false);

  return (
    <BlossomThemeProvider
      theme={isDark ? darkTheme : lightTheme}
      isDark={isDark}
      options={options}
    >
      <MyAppContainer />
    </BlossomThemeProvider>
  );
}
Enter fullscreen mode Exit fullscreen mode

Now, from here you can use all the 20+ components (as of now) to build and awesome blossom UI.
Let's make a login form real quick.

import React, { useCallback, useState } from "react";

import {
  Button,
  Checkbox,
  Text,
  TextInput,
  View,
} from "@react-native-blossom-ui/components";

export function Login() {
  const [isLoading, setIsLoading] = useState(false);
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");

  const [isEmailError, setIsEmailError] = useState(false);
  const [isPasswordError, setIsPasswordError] = useState(false);

  const onLoginPress = useCallback(() => {
    if (!email) {
      setIsEmailError(true);
      return;
    }

    if (!password) {
      setIsPasswordError(true);
      return;
    }

    setIsEmailError(false);
    setIsPasswordError(false);
    // Call the api
    setIsLoading(true);
    setTimeout(() => {
      setIsLoading(false);
    }, 1500);
  }, []);

  return (
    <View style={{ margin: 16 }}>
      <Text typography="h4">Login</Text>
      <TextInput
        label="Email"
        placeholder="abc@gmail.com"
        value={email}
        onChangeText={setEmail}
        containerStyle={{ marginVertical: 8 }}
        error={isEmailError ? "Please enter your email" : ""}
      />
      <TextInput
        label="Password"
        placeholder="Password"
        value={password}
        onChangeText={setPassword}
        containerStyle={{ marginVertical: 8 }}
        secureTextEntry
        error={isPasswordError ? "Please enter a valid password" : ""}
      />
      <Checkbox status="primary" size="small" label="Remember Me" />
      <Button
        isLoading={isLoading}
        title="Login"
        style={{ width: "100%", marginVertical: 16 }}
        onPress={onLoginPress}
      />
    </View>
  );
}
Enter fullscreen mode Exit fullscreen mode

Here's the result of it.

Image description

Bonus Component

You can also use the in-built Select/MultiSelect component which come out of the box with theme support too. For example -


export function SelectClearable() {
  const [selectedValue, setSelectedValue] = useState<number | undefined>(-1)

  return (
    <Select
      options={OPTIONS}
      value={selectedValue}
      clearable
      onValueChange={(value) => setSelectedValue(value)}
    />
  )
}
Enter fullscreen mode Exit fullscreen mode

Thanks for reading, please star this repository if it looks awesome and a good step in react-native community.

Sentry mobile image

Mobile Vitals: A first step to Faster Apps

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read the guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more