# rn_multidevice_layout_scenepkg **Repository Path**: openharmony-sig/rn_multidevice_layout_scenepkg ## Basic Information - **Project Name**: rn_multidevice_layout_scenepkg - **Description**: 这是一个旨在解决 React Native 多设备适配问题的三方库,专为不同设备类型(包括折叠屏、平板、手机等)提供了便捷的支持。该库包含的接口和开箱即用的组件,使开发者能够轻松应对各种设备的布局适配需求。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://gitee.com/openharmony-sig/rn_multidevice_layout_scenepkg - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 2 - **Created**: 2024-12-20 - **Last Updated**: 2025-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🚨 **重要提示 | IMPORTANT** > > **⚠️ 此代码仓已归档。新地址请访问 [rn_multidevice_layout_scenepkg](https://gitcode.com/openharmony-sig/rn_multidevice_layout_scenepkg)。| ⚠️ This repository has been archived. For the new address, please visit [rn_multidevice_layout_scenepkg](https://gitcode.com/openharmony-sig/rn_multidevice_layout_scenepkg).** > --- > # rn_multidevice_layout_scenepkg ## 介绍 这是一个旨在解决 React Native多设备适配问题的三方库,专为不同设备类型(包括折叠屏、平板、手机等)提供了便捷的支持。该库包含的接口和开箱即用的组件,使开发者能够轻松应对各种设备的布局适配需求。 ## 工程目录 ``` . ├─example ├─harmony │ ├─fold.har // 折叠屏turbo接口har包 │ └─fold │ └─src │ └─main │ └─ets │ ├─FoldModule.ets // turbo接口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/openharmony-sig/rn_multidevice_layout_scenepkg)代码仓并执行npm pack获取tgz包。 进入到工程目录并输入以下命令: >**说明:** >#处替换为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)}