Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pulltorefresh): 适配鸿蒙、RN、小程序、H5; RN scrollview 默认事件无法阻止 #2342

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
4 changes: 2 additions & 2 deletions packages/nutui-taro-demo-rn/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const subPackages = [
}
];

export default defineAppConfig({
export default defineAppConfig ({
pages: ['pages/index/index'],
subPackages,
window: {
Expand All @@ -133,4 +133,4 @@ export default defineAppConfig({
navigationBarTitleText: 'NutUI-React',
navigationBarTextStyle: 'black'
}
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
navigationBarTitleText: 'PullToRefresh',
navigationBarTitleText: 'Pulltorefresh'
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default <>button</>;
import Demo from '@/packages/pulltorefresh/demo.taro';
export default Demo;
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@
"author": "szg2008"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "PullToRefresh",
"type": "component",
"cName": "下拉刷新",
Expand Down
11 changes: 6 additions & 5 deletions src/packages/pulltorefresh/demo.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import Taro from '@tarojs/taro'
import { ScrollView, View } from '@tarojs/components'
import Header from '@/sites/components/header'
import { useTranslate } from '@/sites/assets/locale/taro'
import Demo1 from './demos/taro/demo1'
Expand Down Expand Up @@ -27,16 +28,16 @@ const PullToRefreshDemo = () => {
return (
<>
<Header />
<div className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}>
<h2>{translated.basic}</h2>
<ScrollView className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}>
<View className="h2">{translated.basic}</View>
<Demo1 />

<h2>{translated.scrollView}</h2>
<View className="h2">{translated.scrollView}</View>
<Demo2 />

<h2>{translated.primary}</h2>
<View className="h2">{translated.primary}</View>
<Demo3 />
</div>
</ScrollView>
</>
)
}
Expand Down
46 changes: 19 additions & 27 deletions src/packages/pulltorefresh/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React, { useState } from 'react'
import { PullToRefresh, Toast } from '@nutui/nutui-react-taro'
import { Image, View } from '@tarojs/components'
import { PullToRefresh } from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro'
import pxTransform from '@/utils/px-transform'

const Demo1 = () => {
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
const [show, SetShow] = useState(false)
const [toastMsg, SetToastMsg] = useState('')
const toastShow = (msg: any) => {
SetToastMsg(msg)
SetShow(true)
}

return (
<>
<PullToRefresh
Expand All @@ -18,24 +16,25 @@ const Demo1 = () => {
}}
onRefresh={() =>
new Promise((resolve) => {
toastShow('😊')
Taro.showToast({
title: '😊',
icon: 'none',
})
resolve('done')
})
}
renderIcon={(status) => {
return (
<>
{(status === 'pulling' || status === 'complete') && (
<img
alt=""
style={{ height: '26px', width: '36px' }}
<Image
style={{ height: pxTransform(26), width: pxTransform(36) }}
src="https://img13.360buyimg.com/imagetools/jfs/t1/219180/19/37902/438/65fa8cbbF5278d022/5eabe69b64bba791.png"
/>
)}
{(status === 'canRelease' || status === 'refreshing') && (
<img
alt=""
style={{ height: '26px', width: '36px' }}
<Image
style={{ height: pxTransform(26), width: pxTransform(36) }}
src="https://img10.360buyimg.com/imagetools/jfs/t1/230454/20/14523/223/65fab2d1F379c3968/ac35992443abab0c.png"
/>
)}
Expand All @@ -44,26 +43,19 @@ const Demo1 = () => {
}}
>
{list.map((item) => (
<div
<View
style={{
textAlign: 'center',
height: '50px',
lineHeight: '50px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: pxTransform(50),
}}
key={item}
>
{item}
</div>
</View>
))}
</PullToRefresh>
<Toast
type="text"
visible={show}
content={toastMsg}
onClose={() => {
SetShow(false)
}}
/>
</>
)
}
Expand Down
13 changes: 3 additions & 10 deletions src/packages/pulltorefresh/demos/taro/demo2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import { ScrollView } from '@tarojs/components'
import { PullToRefresh, Cell, Toast } from '@nutui/nutui-react-taro'
import { Cell, PullToRefresh } from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo2 = () => {
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
Expand All @@ -14,7 +15,7 @@ const Demo2 = () => {
return (
<>
<ScrollView
style={{ height: '150px' }}
style={{ height: pxTransform(150) }}
scrollY
onScrollEnd={(e) => {
// scrollTop > 0, PullToRefresh 不触发 touchmove 事件。
Expand All @@ -37,14 +38,6 @@ const Demo2 = () => {
))}
</PullToRefresh>
</ScrollView>
<Toast
type="text"
visible={show}
content={toastMsg}
onClose={() => {
SetShow(false)
}}
/>
</>
)
}
Expand Down
47 changes: 19 additions & 28 deletions src/packages/pulltorefresh/demos/taro/demo3.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import React, { useState } from 'react'
import { PullToRefresh, Toast } from '@nutui/nutui-react-taro'
import { Image, Text, View } from '@tarojs/components'
import { PullToRefresh } from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro'
import pxTransform from '@/utils/px-transform'

const Demo1 = () => {
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
const [show, SetShow] = useState(false)
const [toastMsg, SetToastMsg] = useState('')
const toastShow = (msg: any) => {
SetToastMsg(msg)
SetShow(true)
}
return (
<>
<PullToRefresh
type="primary"
onRefresh={() =>
new Promise((resolve) => {
toastShow('😊')
Taro.showToast({
title: '😊',
icon: 'none',
})
resolve('done')
})
}
renderIcon={(status) => {
return (
<>
{(status === 'pulling' || status === 'complete') && (
<img
alt=""
style={{ height: '26px', width: '36px' }}
<Image
style={{ height: pxTransform(26), width: pxTransform(36) }}
src="https://img12.360buyimg.com/imagetools/jfs/t1/232373/2/15010/432/65fab02fF99afdb71/0457cdfa268f92df.png"
/>
)}
{(status === 'canRelease' || status === 'refreshing') && (
<img
alt=""
style={{ height: '26px', width: '36px' }}
<Image
style={{ height: pxTransform(26), width: pxTransform(36) }}
src="https://img14.360buyimg.com/imagetools/jfs/t1/186707/25/42738/223/65fab272F0965554b/eae33de2f17909b8.png"
/>
)}
Expand All @@ -41,26 +39,19 @@ const Demo1 = () => {
}}
>
{list.map((item) => (
<div
<View
style={{
textAlign: 'center',
height: '50px',
lineHeight: '50px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: pxTransform(50),
}}
key={item}
>
{item}
</div>
<Text style={{ color: '#ffffff' }}>{item}</Text>
</View>
))}
</PullToRefresh>
<Toast
type="text"
visible={show}
content={toastMsg}
onClose={() => {
SetShow(false)
}}
/>
</>
)
}
Expand Down
14 changes: 13 additions & 1 deletion src/packages/pulltorefresh/pulltorefresh.harmony.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
bottom: 0;
left: 0;
width: 100%;
color: #1A1A1A;
color: #1a1a1a;
display: flex;
flex-direction: column;
justify-content: center;
Expand All @@ -19,6 +19,18 @@
height: 26px;
margin-bottom: 4px;
}
.nut-pulltorefresh-primary {
background: #ff0f23;
}
.nut-pulltorefresh-primary-content {
color: rgba(255, 255, 255, 0.9);
}
.nut-pulltorefresh-primary-head-content {
color: rgba(255, 255, 255, 0.9);
}
.nut-pulltorefresh-primary-status-text {
color: #ffffff;
}

[dir=rtl] .nut-pulltorefresh-head-content,
.nut-rtl .nut-pulltorefresh-head-content {
Expand Down
9 changes: 7 additions & 2 deletions src/packages/pulltorefresh/pulltorefresh.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@

&-primary {
background: $pulltorefresh-color-primary;
.nut-pulltorefresh-content {

&-content {
color: $color-text-dark;
}

.nut-pulltorefresh-head {
&-head {
&-content {
color: $color-text-dark;
}
}

&-status-text {
color: $white;
}
}
}

Expand Down
Loading