@flarelane/react-native-sdk

中文文档
1.12.0发布于 2026/11/12MITTypeScriptESM + CJS零依赖近 30 天下载 2099

FlareLane react-native SDK

原始使用文档
文档目录7 节
  1. Installation
  2. Region
  3. WebView Bridge (hybrid apps)
  4. react-native-webview
  5. Other webview packages
  6. Notes
  7. License

react-native-flarelane

Welcome to FlareLane!

Installation

npm install @flarelane/react-native-sdk

Region

FlareLane.initialize(projectId, requestPermissionOnLaunch = true, region?)

Projects live in one region. Omit region for the default "us"; projects created in the Seoul region pass "kr":

FlareLane.initialize('YOUR_PROJECT_ID', true, 'kr');

The native SDK validates the value: a malformed region logs an error and stops initialization instead of falling back to "us".

WebView Bridge (hybrid apps)

For apps that embed pages running the FlareLane Web SDK, the native SDK exposes a bridge so identity (deviceId / userId / projectId) and SDK calls (setUserId, setTags, trackEvent, setUserAttributes, syncDeviceData) stay aligned between native and web.

The bridge name and class name match the native Android/iOS SDKs: FlareLaneJavascriptInterface + BRIDGE_NAME. RN ships a library-named adapter that exposes members 1:1 with react-native-webview's prop and callback slots — drop them into your existing <WebView> wiring.

react-native-webview

import { WebView } from 'react-native-webview';
import { FlareLaneJavascriptInterface } from '@flarelane/react-native-sdk/adapters/react-native-webview';

const webViewRef = useRef<WebView>(null);

// `injectedJavaScript` and `injectedJavaScriptBeforeContentLoaded` carry the
// same string, so one variable can be reused across both slots. If you don't
// have existing injection, drop the `myExistingInjection +` part.
const injection =
  myExistingInjection + FlareLaneJavascriptInterface.injectedJavaScript;

<WebView
  ref={webViewRef}
  source={{ uri }}
  injectedJavaScript={injection}
  injectedJavaScriptBeforeContentLoaded={injection}
  onMessage={FlareLaneJavascriptInterface.onMessage(webViewRef)}
/>

If you already have an onMessage handler, wrap the adapter inside it:

onMessage={async (event) => {
  await FlareLaneJavascriptInterface.onMessage(webViewRef)(event);
  myExistingOnMessage(event);
}}

The adapter exposes:

  • FlareLaneJavascriptInterface.BRIDGE_NAME — channel name constant.
  • FlareLaneJavascriptInterface.injectedJavaScript — JS to inject. Includes the react-native-webview channel adapter and the bridge shim. The same string is valid for both injectedJavaScript and injectedJavaScriptBeforeContentLoaded slots.
  • FlareLaneJavascriptInterface.onMessage(webViewRef) — factory that returns a handler for <WebView onMessage={…}>. The ref is used to evaluate response JS (e.g. the syncDeviceData callback) back into the webview.

Other webview packages

This SDK only ships a first-class adapter for react-native-webview. If you use a different webview library, port the adapter implementation (src/adapters/react-native-webview.ts) to your library's slot names — the JS injection and message routing logic are self-contained inside that file.

Notes

  • The injected JS is idempotent — safe to inject twice.
  • Inject before the Web SDK loads. injectedJavaScriptBeforeContentLoaded works on iOS; Android falls back to injectedJavaScript (post-load). Either way the SDK injection is guarded so multiple injections are safe. For Android specifically, avoid loading the Web SDK as an inline synchronous <script> at the very top of <head>, which could fire before the fallback injection lands.
  • setUserAttributes is available on Android, iOS, Flutter, and React Native SDKs with consistent semantics.

License

MIT

版本与发布记录

@flarelane/react-native-sdk 共发布 39 个版本,首次发布于 2021/10/08;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.12.0latest2026/11/123 天前
1.11.32026/09/221 个月前
1.11.22026/08/282 个月前
1.10.22026/08/063 个月前
1.10.02026/06/085 个月前
1.9.42026/05/185 个月前

其他发布通道:next → 1.8.0-1。

关于 @flarelane/react-native-sdk 的常见问题

@flarelane/react-native-sdk 是什么?

FlareLane react-native SDK

如何安装 @flarelane/react-native-sdk?

在项目目录运行 npm install @flarelane/react-native-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flarelane/react-native-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flarelane/react-native-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flarelane/react-native-sdk 可以商用吗?

@flarelane/react-native-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flarelane/react-native-sdk 的下载量有多少?

根据 npm 官方下载统计,@flarelane/react-native-sdk 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,099 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flarelane/react-native-sdk 还在维护吗?

最新版本 1.12.0 发布于 2026/11/12(3 天前);至今共发布 39 个版本,其中过去 12 个月发布了 7 个;首次发布于 2021/10/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。