快速入门
复制一条配置 prompt,包含安装步骤和该插件的完整 Markdown 指南。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-native-loader`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/native-loader/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-native-loader` plugin in my project.如果你更倾向于手动设置,请运行以下命令安装插件,并参考下文针对各平台的具体说明:
-
安装软件包
终端窗口 bun add @capgo/capacitor-native-loaderbunx cap sync -
通过 JavaScript 显示 Native Loader
import { NativeLoader } from '@capgo/capacitor-native-loader';const { id } = await NativeLoader.show({style: 'siri',placement: 'fullscreen',message: 'Preparing workspace',colors: ['#71f6ff', '#8b5cf6', '#ff4ecd', '#fff7ad'],scrimColor: 'rgba(3, 7, 18, 0.42)',interactionMode: 'block',});await doExpensiveWork();await NativeLoader.hide({ id });
快速入门
“快速开始”章节import { NativeLoader } from '@capgo/capacitor-native-loader';
await NativeLoader.configure({ defaults: {} });示例:show
示例:showimport { NativeLoader } from '@capgo/capacitor-native-loader';
const result = await NativeLoader.show();console.log(result);示例:更新
示例:updateimport { NativeLoader } from '@capgo/capacitor-native-loader';
await NativeLoader.update({ id: 'id-123' });常见坑点
标题为“常见坑点”的章节- 仅需初始化一次: 在应用启动阶段运行 setup。
- 原生同步: 运行
bunx cap sync在插件升级后。 - 单一事实来源: 信任
src/definitions.ts在 GitHub 仓库中。
配置默认值
“配置默认值”章节await NativeLoader.configure({ defaults: { style: 'orbit', placement: 'center', size: 96, colors: ['#38bdf8', '#a78bfa'], reducedMotion: 'system', interactionMode: 'passThrough', },});Chrome 风格顶部加载器
“Chrome 风格顶部加载器”章节使用 style: 'chrome' 当你想要熟悉的浏览器顶部进度条,且下方的 WebView 仍需保持可用时。
const { id } = await NativeLoader.show({ style: 'chrome', placement: 'top', colors: ['#4285f4', '#34a853', '#fbbc05', '#ea4335'], thickness: 4, interactionMode: 'passThrough', webView: { mode: 'resize', insets: { top: 12 }, restoreOnHide: true, },});
await NativeLoader.hide({ id, restoreWebView: true });Siri V2 边缘加载器
标题为 “Siri V2 Edge Loader” 的章节使用 style: 'siri-v2' 当加载状态应为 App 边缘的 Native 全屏色彩动效,而非居中的卡片时。
const { id } = await NativeLoader.show({ style: 'siri-v2', placement: 'fullscreen', colors: ['#71f6ff', '#8b5cf6', '#ff4ecd', '#fff7ad'], thickness: 10, scrimColor: 'rgba(3, 7, 18, 0.10)', interactionMode: 'passThrough',});
await NativeLoader.hide({ id });const { id } = await NativeLoader.show({ style: 'ring', message: 'Uploading', progress: 0,});
for await (const progress of uploadFile(file)) { await NativeLoader.setProgress({ id, progress });}
await NativeLoader.hide({ id });调整 WebView 大小
“调整 WebView 大小”章节使用 setWebViewLayout 当 Native Loader 需要占用部分屏幕,同时保持 Web 内容可见且可用时。
await NativeLoader.setWebViewLayout({ mode: 'inset', insets: { top: 96, bottom: 24 }, animated: true,});
await NativeLoader.show({ style: 'wave', placement: 'top', size: 72, message: 'Syncing', interactionMode: 'passThrough',});当 Native Surface 消失时,恢复原始布局:
await NativeLoader.hideAll({ restoreWebView: true });Lottie 与图片加载器
“Lottie 与图片加载器”章节将 Lottie JSON 或图片资源打包进 Native App,并从 JavaScript 中进行引用。
await NativeLoader.show({ style: 'lottie', placement: 'center', asset: { type: 'lottie', source: 'rocket-loader.json', loop: true, },});await NativeLoader.show({ style: 'image', placement: 'bottom', asset: { type: 'image', source: 'loader-frame', },});Native Swift 调用
标题为 “Native Swift Calls” 的章节其他 iOS 插件可以直接调用该共享加载器。
import CapgoCapacitorNativeLoader
let id = NativeLoader.shared.show(options: [ "style": "siri", "placement": "fullscreen", "message": "Opening secure session", "interactionMode": "block"])
NativeLoader.shared.setProgress(id: id, progress: 0.6)NativeLoader.shared.hide(id: id)Native Kotlin 调用
标题为 “Native Kotlin Calls” 的章节其他 Android 插件可以通过 Kotlin 或 Java 调用该公共对象。
import app.capgo.nativeloader.NativeLoader
val id = NativeLoader.show( activity = activity, options = mapOf( "style" to "orbit", "placement" to "fullscreen", "message" to "Loading profile", "interactionMode" to "block", ), webView = bridge.webView,)
NativeLoader.setProgress(id, 0.6)NativeLoader.hide(id)| 选项 | 类型 | 描述 |
|---|---|---|
style | 'siri' | 'siri-v2' | 'chrome' | 'orbit' | 'ring' | 'pulse' | 'dots' | 'bars' | 'wave' | 'halo' | 'lottie' | 'image' | 加载器渲染器 |
placement | 'center' | 'top' | 'bottom' | 'left' | 'right' | 'fullscreen' | 'around' | 'custom' | 原生视图位置 |
interactionMode | 'passThrough' | 'block' | 'loaderOnly' | 触摸处理 |
backgroundColor | string | 遮罩颜色(含透明度) |
scrimColor | string | 全屏或屏幕周围的遮罩颜色 |
colors | string[] | 加载器渐变色 |
progress | number | 确定进度值来源 0 至 1 |
autoHide | number | 自动隐藏前的毫秒数 |
asset | object | Lottie 或图像资源源 |
使用 reducedMotion: 'system' 以遵循用户的平台动画设置。