Skip to content

Getting started ​

Requirements ​

PlatformMinimum
AndroidminSdk 24
iOS, macOSiOS 15, macOS 12, Swift 5.9
WindowsWindows 10 version 1809 (build 17763), Windows App SDK 1.8, .NET 8
WebAny browser with <canvas> and custom elements

Install ​

sh
npm install @loader-kit/web
sh
yarn add @loader-kit/web
sh
pnpm add @loader-kit/web
kotlin
dependencies {
    implementation("io.github.maitrungduc1410:loaderkit-core:<version>")
    // Jetpack Compose (includes loaderkit-core):
    implementation("io.github.maitrungduc1410:loaderkit-compose:<version>")
}
swift
dependencies: [
    .package(url: "https://github.com/maitrungduc1410/loader-kit.git", from: "<version>"),
],
targets: [
    .target(name: "App", dependencies: [.product(name: "LoaderKit", package: "loader-kit")]),
]
ruby
pod 'LoaderKit', :git => 'https://github.com/maitrungduc1410/loader-kit.git', :tag => '<version>'
sh
dotnet add package LoaderKit.WinUI
  • Replace <version> with the latest release from the GitHub releases. Tags have no v prefix.
  • Android: both artifacts are on Maven Central, so mavenCentral() must be in your repositories.
  • Apple: in Xcode you can also use File > Add Package Dependencies and enter the repository URL. The pod is not on the CocoaPods trunk: point the Podfile at the repository and a release tag.
  • Windows: LoaderKit.WinUI brings LoaderKit.Core with it.
  • React Native: see React Native.

Your first indicator ​

Built-in or progress?

  • No percentage, ever (waiting for a request, pull to refresh): use a built-in indicator, as below. There are 50 styles to pick from.
  • The task has progress, even if it is unknown at first (a download, an upload, processing a file): use a progress indicator. Start it indeterminate with value null (nil in Swift), then set a value once you know it. It is the same component, so nothing else changes.

Each snippet shows BallSpinFadeLoader in purple, 1.5 times faster than normal.

tsx
import { LoaderKit } from '@loader-kit/web/react';

<LoaderKit indicator="BallSpinFadeLoader" color="#7c3aed" speed={1.5} />
vue
<script setup lang="ts">
import { LoaderKit } from '@loader-kit/web/vue';
</script>

<template>
  <LoaderKit indicator="BallSpinFadeLoader" color="#7c3aed" :speed="1.5" />
</template>
svelte
<script lang="ts">
  import { LoaderKit } from '@loader-kit/web/svelte';
</script>

<LoaderKit indicator="BallSpinFadeLoader" color="#7c3aed" speed={1.5} />
html
<script type="module">
  import '@loader-kit/web/element';
</script>

<loader-kit indicator="BallSpinFadeLoader" color="#7c3aed" speed="1.5"></loader-kit>
ts
import { LoaderKitView } from '@loader-kit/web';

const view = new LoaderKitView(document.querySelector('#loader')!, {
  indicator: 'BallSpinFadeLoader',
  color: '#7c3aed',
  speed: 1.5,
});
xml
<io.github.maitrungduc1410.loaderkit.LoaderKitView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:indicator="BallSpinFadeLoader"
    app:indicatorColor="#7C3AED"
    app:speed="1.5" />
kotlin
import io.github.maitrungduc1410.loaderkit.LoaderKitView

val loader = LoaderKitView(context).apply {
    indicator = "BallSpinFadeLoader"
    color = Color.parseColor("#7C3AED")
    speed = 1.5
}
container.addView(loader)
kotlin
import io.github.maitrungduc1410.loaderkit.compose.LoaderKitIndicator

LoaderKitIndicator(
    indicator = "BallSpinFadeLoader",
    modifier = Modifier.size(48.dp),
    color = Color(0xFF7C3AED),
    speed = 1.5,
)
swift
import LoaderKit

let loader = LoaderKitView(indicator: "BallSpinFadeLoader")
loader.color = .systemPurple
loader.speed = 1.5
view.addSubview(loader)
swift
import LoaderKit
import SwiftUI

struct LoadingView: View {
    var body: some View {
        LoaderKitIndicator("BallSpinFadeLoader")
            .color(.purple)
            .speed(1.5)
            .frame(width: 48, height: 48)
    }
}
xml
<Page xmlns:lk="using:LoaderKit.WinUI">
    <lk:LoaderKitIndicator Indicator="BallSpinFadeLoader" Color="#7C3AED" Speed="1.5" />
</Page>
csharp
using LoaderKit.WinUI;
using Microsoft.UI;

var indicator = new LoaderKitIndicator
{
    Indicator = "BallSpinFadeLoader",
    Color = ColorHelper.FromArgb(255, 0x7C, 0x3A, 0xED),
    Speed = 1.5,
};

Result:

Default size ​

Every view is 40 by 40 (dp, points, effective pixels or CSS pixels) unless you size it. The indicator is drawn in the largest square that fits, centered in the view. So a wide view draws a centered indicator, not a stretched one.

Stopping the indicator ​

Indicators start animating as soon as they are shown. When the work is done, stop them. By default a stopped indicator draws nothing.

ts
view.stop();      // or view.animating = false
view.destroy();   // when you remove it for good
kotlin
loader.stop()     // or loader.isAnimating = false
kotlin
LoaderKitIndicator("BallSpinFadeLoader", animating = isLoading)
swift
loader.stopAnimating()   // or loader.isAnimating = false
swift
LoaderKitIndicator("BallSpinFadeLoader").animating(isLoading)
csharp
indicator.IsAnimating = false;

See Playback for speed, freezing a frame and reduced motion.

Next steps ​

Released under the MIT License.