# rn_multidevice_layout_scenepkg **Repository Path**: ohadss/rn_multidevice_layout_scenepkg ## Basic Information - **Project Name**: rn_multidevice_layout_scenepkg - **Description**: RN framework-oriented multi-device layout scenario package. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2024-11-05 - **Last Updated**: 2025-01-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

rn_multidevice_layout_scenepkg

## 介绍 这是一个旨在解决 React Native 多设备适配问题的三方库,专为不同设备类型(包括折叠屏、平板、手机等)提供了便捷的支持。该库包含的接口和开箱即用的组件,使开发者能够轻松应对各种设备的布局适配需求。 ## 工程目录 ``` . ├─harmony │ │ fold.har // 折叠屏turbo接口har包 │ │ │ └─fold │ └─src │ └─main │ └─ets │ │ FoldModule.ets // tur接口ArkTS实现 │ │ FoldModulePackage.ets // FoldModulesFactory │ │ FoldModuleSpec.ts // turbo接口 │ │ │ └─core │ FoldConfig.ts │ └─src │ index.ts // RN模块导出 │ ├─component │ FoldSplitContainer.tsx // 折叠屏高阶组件 │ ├─config │ breakpoints.ts // 断点配置类 │ ├─hooks │ useBreakpointValue.ts //断点hook │ └─turbo NativeFoldModule.ts // RN turbo接口 ``` ## 安装与使用 请拉取[rn_multidevice_layout_scenepkg](https://gitee.com/ohadss/rn_multidevice_layout_scenepkg)代码仓并执行npm pack获取 tgz 包。 进入到工程目录并输入以下命令: > [!TIP] # 处替换为 tgz 包的路径 #### **npm** ```bash npm install rn_multidevice_layout_scenepkg@file:# ``` #### **yarn** ```bash yarn add rn_multidevice_layout_scenepkg@file:# ``` 下面的代码展示了这个库的基本使用场景: ```jsx const TestSample = () => { const [foldCreaseRegion, setFoldCreaseRegion] = useState([]); const [foldStatus, setFoldStatus] = useState(''); const [breakpoints, setBreakpointsState] = useState({}); const [isDeviceFoldable, setIsDeviceFoldable] = useState(false); useEffect(() => { const checkFoldable = () => { // 判断当前设备是否可折叠 const foldable = Fold.isFoldable(); setIsDeviceFoldable(foldable); if (foldable) { // 获取折痕区域 setFoldCreaseRegion(Fold.getFoldCreaseRegion()); // 获取当前折叠屏状态 setFoldStatus(Fold.getFoldStatus()); } }; checkFoldable(); // 监听折叠屏状态变化 Fold.addFoldListener((foldStatus) => { console.log('折叠屏状态发生变化', foldStatus); }); return () => { // 销毁监听折叠屏状态变化 Fold.removeFoldListener(); }; }, []); const handleGetBreakpoints = () => { setBreakpointsState(getBreakpoints()); }; const handleSetBreakpoints = () => { // 设置断点区间 setBreakpoints({ base: 320, md: 768, lg: 1024, }); }; const handleGetFoldStatus = () => { if (isDeviceFoldable) { // 获取当前折叠屏状态 setFoldStatus(Fold.getFoldStatus()); } }; const color = useBreakpointValue({ // 根据不同断点设置不同的颜色 base: 'red', xs: 'blue', sm: 'green', md: 'yellow', lg: 'purple', xl: 'orange', }); // FoldSplitContainer 主要区域 const primaryRender = () => ( Responsive Color Text Is Device Foldable: {isDeviceFoldable ? 'Yes' : 'No'} {isDeviceFoldable && ( <> Fold Crease Region: {JSON.stringify(foldCreaseRegion)}