ios - Correct approach to specific style code for small and big iOS screen in React Native?
问题描述
Is there an easy way to make a different style (like smaller and bigger buttons etc. ) for small size ios devices and the big ones in React Native? Like here (https://reactnative.dev/docs/platform-specific-code#platform-specific-extensions) when I need different styles for a specific platform iOS and Android in React Native?
Thanks
解决方案
All is explained in your link.
Two solutions:
- One component where you handle the platform
:
import { Platform } from 'react-native';
...
<Button style={Platform.OS === 'ios' ? styles.iosButton: styles.androidButton} />
- Two components for each platforms
:
BigButton.ios.js
BigButton.android.js
...
import BigButton from './BigButton';
Importing like this will load the correct component depending of the platform
To adjust depending of the screen size you can use Dimensions
import { Dimensions } from 'react-native';
const windowWidth = Dimensions.get('window').width;
<View style={windowWidth > 1200 ? styles.big_screen : styles.small_screen}>
...
</View>
推荐阅读
- arrays - 使用来自 textviews 数组的 func resign 第一响应者
- resharper - 在 Rider 和 ReSharper 之间共享代码样式设置
- c# - UseJwtBearerAuthentication 不使用令牌进行授权.NET
- java - 不同的地图具有相同的哈希码
- python - Python Redis 队列
- vb.net - VB 命令请求
- python - 在 Python 文件提交的情况下 spark-submit 命令不起作用
- python - Python:用多处理替换 xml 元素
- c# - 为什么 Selenium C# Chrome 不将会话数据存储到用户数据目录?
- installation - 在 Laravel 6 上从 Maddhatter/laravel-fullcalendar 安装软件包时出现问题