咦 大家有见网友的经验吗?
在还没见面前是否都是以照片来判断这个人是不是自己的菜?
网站也有一个时间是还没 loading 好的时间差
今天来教大家做一个 shap 骨架屏,在你还没与真正的元件见面的时候
先用照骗跟形状住进他心中!直到与他相见 XD
今天要介绍的套件是 react-native-skeleton-placeholder
这个插件需要安装 @react-native-masked-view/masked-view and react-native-linear-gradient
npm install @react-native-masked-view/masked-view react-native-linear-gradient --save
cd ios
pod install
npm install react-native-skeleton-placeholder --save
cd ios
pod install
import React from 'react';
import { View } from 'react-native';
import SkeletonPlaceholder from 'react-native-skeleton-placeholder';
const Placeholder = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<SkeletonPlaceholder>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<View style={{ width: 60, height: 60, borderRadius: 50 }} />
<View style={{ marginLeft: 20 }}>
<View style={{ width: 120, height: 20, borderRadius: 4 }} />
<View
style={{ marginTop: 6, width: 80, height: 20, borderRadius: 4 }}
/>
</View>
</View>
</SkeletonPlaceholder>
</View>
);
};
export default Placeholder;
我长这样 ~~~
import React from 'react';
import { View } from 'react-native';
import SkeletonPlaceholder from 'react-native-skeleton-placeholder';
const Placeholder = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<SkeletonPlaceholder>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<View style={{ width: 60, height: 60, borderRadius: 50 }} />
<View style={{ marginLeft: 20 }}>
<View style={{ width: 120, height: 20, borderRadius: 4 }} />
<View
style={{ marginTop: 6, width: 80, height: 20, borderRadius: 4 }}
/>
</View>
</View>
// add--
<View>
<View
style={{ marginTop: 6, width: 100, height: 30, borderRadius: 50 }}
/>
</View>
// --end
</SkeletonPlaceholder>
</View>
);
};
export default Placeholder;
就会多出现一条线拉!!
import Placeholder from '@src/components/Placeholder'
const [ isloading, setLoading ]= useState(true)
// 在页面读取好资料後将使用 setLoading(false)
// 运用 isloading? 来判断要是用画面还是 Placeholder
其实这个套件就是照着原本画面刻出一个一样的影子!再来判断是否 loading 完成,简简单单的使用,就算是看不到本人也看得到背影~~~让画面不空白不突然展开 :P
Day22 done~ 请多多指教
>>: Day 22 Ruby include vs extend vs prepend
建立 Mock Server 後,前端工程师就失去耍废时间不需要等後端做好才能串接。 前端工程师心里...
立即函式特点: 立即执行 无法在函式外再次执行 接着我们来看立即函式的语法 (function() ...
在正式使用 docker 之前,需要先知道以下三个元素:映像档 ( Image )、容器 ( Con...
今年很荣幸有机会参加 iT 铁人赛,其一方面是要强迫自己对单元测试有更多一点的认识;另一方面是想透过...
昨天我们新增了一个 UserServiceWithFile 操作本地端档案来管理使用者资料,而档案的...