1k-ui-recipes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOneKey UI Recipes
OneKey UI 实用解决方案
Bite-sized solutions for common UI issues.
针对常见UI问题的轻量解决方案。
Quick Reference
快速参考
| Recipe | Guide | Key Points |
|---|---|---|
| iOS Tab Bar Scroll Offset | ios-tab-bar-scroll-offset.md | Use |
| Smooth State Transitions | start-view-transition.md | Wrap heavy state updates in |
| Horizontal Scroll in Collapsible Tab Headers | collapsible-tab-horizontal-scroll.md | Bidirectional |
| Android Bottom Tab Touch Interception | android-bottom-tab-touch-intercept.md | Temporary — |
| 解决方案 | 指南文档 | 核心要点 |
|---|---|---|
| iOS标签栏滚动偏移 | ios-tab-bar-scroll-offset.md | 在iOS标签页中使用 |
| 流畅状态过渡 | start-view-transition.md | 在Web端通过将大量状态更新逻辑包裹在 |
| 可折叠标签头中的横向滚动 | collapsible-tab-horizontal-scroll.md | 双向 |
| Android底部标签触摸拦截 | android-bottom-tab-touch-intercept.md | 临时方案 — 在 |
Critical Rules Summary
核心规则总结
1. iOS Tab Bar Scroll Content Offset
1. iOS标签栏滚动内容偏移
Use to add dynamic to scroll containers inside tab pages. Returns tab bar height on iOS, on other platforms.
useScrollContentTabBarOffsetpaddingBottomundefinedtypescript
import { useScrollContentTabBarOffset } from '@onekeyhq/components';
const tabBarHeight = useScrollContentTabBarOffset();
<ScrollView contentContainerStyle={{ paddingBottom: tabBarHeight }} />使用为标签页内的滚动容器添加动态。该方法在iOS平台返回标签栏高度,在其他平台返回。
useScrollContentTabBarOffsetpaddingBottomundefinedtypescript
import { useScrollContentTabBarOffset } from '@onekeyhq/components';
const tabBarHeight = useScrollContentTabBarOffset();
<ScrollView contentContainerStyle={{ paddingBottom: tabBarHeight }} />2. Smooth State Transitions with startViewTransition
startViewTransition2. 使用startViewTransition
实现流畅状态过渡
startViewTransitionWrap heavy state updates in — fade on web/desktop via View Transition API, fallback on native.
startViewTransitionsetTimeouttypescript
import { startViewTransition } from '@onekeyhq/components';
startViewTransition(() => {
setIsReady(true);
});将大量状态更新逻辑包裹在中——在Web/桌面端通过View Transition API实现淡入淡出效果,在原生端使用作为降级方案。
startViewTransitionsetTimeouttypescript
import { startViewTransition } from '@onekeyhq/components';
startViewTransition(() => {
setIsReady(true);
});3. Horizontal Scroll in Collapsible Tab Headers (Native)
3. 可折叠标签头中的横向滚动(原生端)
When placing a horizontal scroller inside of collapsible tabs, use that handles both directions — horizontal drives , vertical calls on the focused tab's ScrollView via .
renderHeaderGesture.Pan()translateXscrollToCollapsibleTabContexttypescript
import { CollapsibleTabContext } from '@onekeyhq/components';Do NOT import directly from. Always use thereact-native-collapsible-tab-view/src/Contextre-export.@onekeyhq/components
在可折叠标签的中放置横向滚动组件时,使用支持双向的——横向手势控制,纵向手势通过调用当前聚焦标签的ScrollView的方法。
renderHeaderGesture.Pan()translateXCollapsibleTabContextscrollTotypescript
import { CollapsibleTabContext } from '@onekeyhq/components';请勿直接从导入,始终使用react-native-collapsible-tab-view/src/Context提供的重导出版本。@onekeyhq/components
4. Android Bottom Tab Touch Interception (Temporary Workaround)
4. Android底部标签触摸拦截(临时修复方案)
Temporary fix — the root cause isintercepting touches even when hidden. This workaround should be removed once the upstream issue is fixed.react-native-bottom-tabs
On Android, intercepts touches in the tab bar region even when the tab bar is . Buttons near the bottom of the screen become unclickable. Fix by creating a variant that wraps buttons with + :
react-native-bottom-tabsGONE.android.tsxGestureDetectorGesture.Tap()typescript
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { runOnJS } from 'react-native-reanimated';
const tapGesture = useMemo(
() => Gesture.Tap().onEnd(() => { 'worklet'; runOnJS(onPress)(); }),
[onPress],
);
<GestureDetector gesture={tapGesture}>
<View>
<Button>Label</Button>
</View>
</GestureDetector>Usefile extension so other platforms are unaffected..android.tsx
临时修复 — 根本原因是即使在标签栏隐藏时仍会拦截触摸事件。待上游问题修复后,应移除该方案。react-native-bottom-tabs
在Android平台,会在标签栏区域拦截触摸事件,即使标签栏已设置为状态,导致屏幕底部附近的按钮无法点击。修复方法是创建变体文件,使用 + 包裹按钮:
react-native-bottom-tabsGONE.android.tsxGestureDetectorGesture.Tap()typescript
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { runOnJS } from 'react-native-reanimated';
const tapGesture = useMemo(
() => Gesture.Tap().onEnd(() => { 'worklet'; runOnJS(onPress)(); }),
[onPress],
);
<GestureDetector gesture={tapGesture}>
<View>
<Button>Label</Button>
</View>
</GestureDetector>使用文件扩展名,避免影响其他平台。.android.tsx
Related Skills
相关技能
- - Platform-specific development
/1k-cross-platform - - Performance optimization
/1k-performance - - General coding patterns
/1k-coding-patterns
- - 跨平台开发
/1k-cross-platform - - 性能优化
/1k-performance - - 通用编码模式
/1k-coding-patterns