Introduction
@meng-xi/unix-utils is a utility library for uni-app x. Together with unix-router, it belongs to MengXi-Studio and follows the same engineering paradigm:
- UTS source distribution:
mainpoints directly toutssdk/index.uts, and the uni-app x build chain compiles it on the fly for the target platform (Web / Mini Program → JS, Android → Kotlin, iOS → Swift); - Strongly typed UTS: object types defined with
type, enums defined with literal unions, noundefined, strict boolean conditions; - Platform differences converge inside the library: business code is written once, and platform-specific logic is isolated inside the library via conditional compilation (
#ifdef).
The library currently ships with two modules: toast (a full-platform compatibility wrapper around uni.showToast) and modal (a full-platform compatibility wrapper around uni.showModal, since v0.2.0).
Why You Need It
The native uni.showToast of uni-app x behaves noticeably differently across the five platforms (Android / iOS / Web / WeChat / HarmonyOS). All of the following facts come from the official docs and official examples (verified in October 2026):
| Difference | Current state |
|---|---|
icon valid values are not aligned | fail only takes effect on Alipay and Douyin Mini Programs; exception only on Alipay; behavior on the other platforms is undefined |
position is unusable | Only takes effect on App, and Android only supports bottom (top / center are not supported yet); once set, the icon stops working and the toast cannot be hidden via uni.hideToast() |
| Inconsistent lifecycle binding | On iOS / WeChat / Web the toast is bound to the page and disappears when the page closes; on Android bottom is a system Toast bound to the App |
Inconsistent title truncation | On WeChat, with the success / loading icons the title shows at most 7 Chinese characters and is truncated beyond that; the limits differ across platforms |
| Missing warning icon | There is no warning icon natively; extended icons such as warning are simply not supported |
| Coarse error info | Failures carry only errCode + errMsg, lacking structured failure info about "which parameter, which platform" |
unix-utils smooths over these differences with a single showToast API.
The same applies to modal. The main differences of the native uni.showModal:
| Difference | Current state |
|---|---|
| Incomplete return values | The cancel field is missing on some platforms; business code must null-check to distinguish confirm / cancel |
| Inconsistent color formats | Color format support varies across platforms (named colors / 8-digit alpha colors silently fall back to the default color on some platforms, without errors) |
| Button text truncation | Button text is platform-constrained beyond 4 characters on WeChat / HarmonyOS |
| Coarse error info | Failures carry only errCode + errMsg, lacking structured failure info about "which parameter, which platform" |
unix-utils smooths over these differences with a single showModal API (App / Web use self-drawn channels; WeChat / HarmonyOS use the native channel with fallback traces).
Two-Layer Compatibility Model
Compatibility differences fall into two layers, where the library's ability to eliminate them — and its guarantees — differ:
Functionality layer (whether parameter semantics take effect on each platform) — fully eliminated through in-library normalization:
fail/exceptionicons are normalized toerror(really rendered on the self-drawn channel);- All three
positionvalues (top/center/bottom) are fully supported on the App / Web self-drawn channels; titlelength follows a unified per-platform truncation policy (7 Chinese characters on WeChat, 20 characters + ellipsis on HarmonyOS);- Failure info is structured as
ToastFail(errSubject/param/platform).
Presentation layer (visual style, lifecycle binding, duration granularity, framework-level bugs) — eliminated directly on App / Web by the self-drawn channel; the remaining platforms (WeChat / HarmonyOS) keep the native channel, managed by three principles:
- Predictable: all residual differences are documented in the parameter normalization matrix and the docs — no hidden behavior;
- Visible: when a fallback happens, the
failcallback returns structured ToastFail so business code can perceive it; - Replaceable: when stronger presentation is needed, the App-side UTS window-attachment channel directly eliminates all presentation-layer differences on that platform.
Channel Architecture
Each platform automatically selects the optimal channel — zero configuration for business code:
| Platform | toast channel | modal channel |
|---|---|---|
| App-Android / App-iOS | UTS direct attachment to system windows (position / warning / mask all take effect; falls back to uni.showToast on failure) | UTS direct attachment with self-drawing (editable / alpha colors fully effective) |
| Web | Self-drawn DOM singleton | Self-drawn DOM singleton |
| WeChat / HarmonyOS | Native uni.showToast (unsupported parameters fall back with a trace) | Native uni.showModal (unsupported parameters fall back with a trace) |
See Channel Architecture and Fallback for details.
Capabilities at a Glance
| Capability | Description |
|---|---|
| Fully aligned parameters | title / icon / image / mask / duration / position / success / fail / complete are all preserved — zero migration cost |
| icon superset | 6 native values + the extended warning; fail / exception are normalized or really rendered on each platform |
| Three position values | top / center / bottom are fully supported on the App / Web self-drawn channels (position semantics finalized in v0.7.2: 10% from the edge) |
| Dual-track API | Callback-style showToast (primary) + Promise-style showToastAsync (auxiliary) |
| Semantic shortcuts | showToastSuccess / showToastError / showToastInfo, one line each |
| Global defaults | configureToast presets duration / icon / mask at the project level |
| Reliable hiding | hideToast reliably hides toasts on the self-drawn channels (including the position variant) |
| Structured fallback | ToastFail.errCode (1001 invalid parameter / 2001 platform unsupported) + param / platform for precise locating |
| Strong typing | Every ToastOptions field except title is optional; icon / position are literal union types |
| modal fully aligned parameters | title / content / showCancel / cancelText / cancelColor / confirmText / confirmColor / editable / placeholderText and the callbacks are all preserved — zero migration cost |
| modal constant return values | ModalResult's confirm / cancel are always present and mutually exclusive (eliminating missing cancel field differences across platforms) |
| modal dual-track + alert | Callback-style showModal + Promise-style showModalAsync (canceling does not count as failure); showModalAlert, a one-line single-confirm-button call |
| modal global defaults | configureModal presets button texts and colors at the project level |
| modal self-drawn channels | App / Web self-drawn: real editable input (content as the initial value, cursor at the end), full alpha color support, mask taps never close; body text taller than 60% of the screen is height-capped and scrolls |
Who Is It For
- You need consistent toast behavior across platforms: one API set covers the five platforms, with predictable and perceivable parameter fallbacks.
- You are fed up with native toast / modal differences: unusable position, misaligned icons per platform, WeChat's 7-character truncation, modal's missing return-value fields — the library handles them all.
- You want strong typing with zero dependencies: UTS source distribution, introducing no third-party UI dependencies.
Next Steps
- Want to get hands-on right away? Start with Installation or Getting Started.
- Want to understand the platform-specific behavior details? See Channel Architecture and Fallback.
