@bittingz/expo-widgets

中文文档
3.0.2发布于 2025/07/08MITTypeScriptCommonJS零依赖近 30 天下载 1.4万

An expo module that allows you to make native widgets in iOS and android

原始使用文档
文档目录8 节
  1. Installation
  2. Setup
  3. Overriding xcode options
  4. Running the example project
  5. Troubleshooting Android
  6. Need Custom Fonts?
  7. Need Development?
  8. Thanks!

expo-widgets

An expo module that allows you to make native widgets in iOS and android.

Installation

Use v1 packages for expo 49, or v2 for expo 51+.

npx expo install @bittingz/expo-widgets

Setup

See the example project for more clarity. You can omit the android or ios folders and setup if you only wish to support one platform.

  1. Create a folder where you want to store your widget files.
  2. In your plugins array (app.config.{js/ts} add:
[
    "@bittingz/expo-widgets",
    {
        ios: {
            src: "./src/my/path/to/ios/widgets/folder",
            devTeamId: "your apple dev team ID",
            mode: "production",                        
            moduleDependencies: [],
            useLiveActivities: false,
            frequentUpdates: false,
            entitlements: {
                "any xcode entitlement the widget needs": "entitlement value"
            }
        },
        android: {
            src: "./src/my/path/to/android/widgets/folder",
            widgets: [
                {
                    "name": "MyWidgetProvider",
                    "resourceName": "@xml/my_widget_info"
                }
            ],
            distPlaceholder: "optional.placeholder"
        }                      
    }
],
  1. Within your iOS widget folder create a Module.swift file, Widget Bundle, Assets.xcassets, and Widget swift files.
  2. Your android folder should mimic android studio setup, so it has two subfolder paths: /android/main/java/package_name and /android/res/.... The package_name is currently being worked on for adjusting the name. Inside you place your widget.kt files. The res folder should contain your assets, the same as in android studio.
  3. If you have any swift files you need to use within Module.swift, simply add them to the moduleDependencies array in your app.config. This is particularly useful for data models between the module and widget.
  4. To share data between your app and widgets you can use a variety of methods, but the easiest way is to use UserPreferences. This plugin automatically handles it for you, so all you have to do is make sure to use a suiteName with the correct format. See the example project.
  5. If you want to use custom fonts in your iOS widget, use my expo-native-fonts package; see the example project for usage. Android widgets work well with resource folders and don't require additional dependencies.
  6. For android, set resourceName to your file name in /res/xml/***_info.xml
  7. For android apps which require multiple distributions with different package names you can use distPlaceholder which will replace all instances of the provided placeholder in widget source files with your app.config.(json/ts/js). So if your source files include "package com.company.app" and "import com.company.app" and you have two distributions (com.company.app for prod and dev.company.app for dev) then setting distPlaceholder to com.company.app will replace all package and import references to the correct distribution each build. You can omit this field if it's not relevant to you. iOS requires no configuration for multiple distribution apps.

Overriding xcode options

You can override xcode options in app.json (all props are optional):

"@bittingz/expo-widgets",
{
    "ios": {
        ...
        xcode: {
            appExtAPI: true, // sets APP_EXTENSION_API_ONLY in the podfile
            configOverrides: {
                // key value pairs e.g. SWIFT_VERSION: '5.0',
            },
            entitlements: {}, // key value pairs
        },
    }
}

The configOverrides properties are the xcodeproj values and must match case exactly.

Running the example project

cd example
npm run prebuild:ios
npm run ios
OR
npm run prebuild:android
npm run android

Troubleshooting Android

If you use R in your widget kotlin file to get layouts, you may get an unresolved reference error for R. In this case, simply add "package your.appconfig.packageid.R", delete your android folder and rebuild.

Need Custom Fonts?

Give my other expo module a try. You'll need to put the fonts config before the widgets config.

Need Development?

If you need widgets designed & developed, reach out for more details.

Thanks!

A huge thanks to gashimo for a great baseline to start from.

版本与发布记录

@bittingz/expo-widgets 共发布 119 个版本,首次发布于 2023/07/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.2latest2025/07/081.3 年前
3.1.0-beta.6beta2025/07/071.3 年前
3.1.0-beta.52025/07/071.3 年前
3.1.0-beta.42025/07/071.3 年前
3.1.0-beta.32025/07/071.3 年前
3.1.0-beta.22025/07/071.3 年前

其他发布通道:next → 2.0.0-next,beta → 3.1.0-beta.6。

关于 @bittingz/expo-widgets 的常见问题

@bittingz/expo-widgets 是什么?

An expo module that allows you to make native widgets in iOS and android

如何安装 @bittingz/expo-widgets?

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

@bittingz/expo-widgets 支持 TypeScript 吗?

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

@bittingz/expo-widgets 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bittingz/expo-widgets 可以商用吗?

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

@bittingz/expo-widgets 的下载量有多少?

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

@bittingz/expo-widgets 还在维护吗?

最新版本 3.0.2 发布于 2025/07/08(1.3 年前);至今共发布 119 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/07/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。