Open dragonwong opened 5 years ago
今天在读人家源码时发现了一个rn样式的骚写法:
import { StyleSheet, Platform, } from 'react-native'; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#eee', ...Platform.select({ ios: { shadowColor: 'rgba(0,0,0,0.2)', shadowOpacity: 1, shadowOffset: { height: 2, width: 2, }, shadowRadius: 2, }, android: { elevation: 0, marginHorizontal: 30, }, }), }, });
以上代码有两个骚处:
Platform.select()
elevation
今天在读人家源码时发现了一个rn样式的骚写法:
以上代码有两个骚处:
Platform.select()
这个骚写法可以很方便地做平台适配;elevation
这个是安卓下的阴影实现