Skip to content

Commit 2561c80

Browse files
Merge pull request #6 from handsomeliuyang/release-3.6.8-app-kxj
完成RootPortal组件与吸顶布局组件(StickyHeader、StickySection)开发
2 parents 772c212 + 5bc65b6 commit 2561c80

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

examples/mini-program-example/src/pages/index/index.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {View, Text,Image,GridView,ListView} from '@tarojs/components'
2-
import {useLoad} from '@tarojs/taro'
1+
import { View, Text, Image, GridView, ListView, RootPortal, StickyHeader, StickySection } from '@tarojs/components'
2+
import { useLoad } from '@tarojs/taro'
33
import './index.scss'
44

55
const grid_data = [
@@ -39,9 +39,29 @@ export default function Index() {
3939
<View className='index'>
4040
<Text>Hello world!</Text>
4141

42-
<GridView columnNum={3} data={grid_data} columnItem={(childItem, i,index) => (
42+
<RootPortal enable={false} style={{
43+
position: 'absolute',
44+
background: '#212121',
45+
width: '80%',
46+
left: '10%',
47+
top: '50%',
48+
borderRadius: '20px',
49+
display: 'flex',
50+
flexDirection: 'column'
51+
}}>
52+
<Text>Hello RootPortal!</Text>
53+
<Text>Hello RootPortal!</Text>
54+
</RootPortal>
55+
<StickyHeader>
56+
<StickySection style={{background: '#aaaaaa'}}>
57+
吸顶布局容器测试
58+
</StickySection>
59+
</StickyHeader>
4360

44-
<View key={`grid-group-item-${index}`} onClick={() => ( console.log("childItem "+childItem.value+" i "+i+" index "+index) )}>
61+
<GridView columnNum={3} data={grid_data} columnItem={(childItem, i, index) => (
62+
63+
<View key={`grid-group-item-${index}`}
64+
onClick={() => (console.log('childItem ' + childItem.value + ' i ' + i + ' index ' + index))}>
4565
{childItem.image && (
4666
<Image
4767
src={childItem.image}
@@ -53,11 +73,11 @@ export default function Index() {
5373
</Text>
5474
</View>
5575

56-
)}/>
76+
)} />
5777

5878
<ListView orientation={'vertical'} data={grid_data} columnItem={(childItem, i) => (
5979

60-
<View key={`list-group-item-${i}`} onClick={() => ( console.log("childItem "+childItem.value+" i "+i) )}>
80+
<View key={`list-group-item-${i}`} onClick={() => (console.log('childItem ' + childItem.value + ' i ' + i))}>
6181
{childItem.image && (
6282
<Image
6383
src={childItem.image}
@@ -69,7 +89,7 @@ export default function Index() {
6989
</Text>
7090
</View>
7191

72-
)}/>
92+
)} />
7393

7494
</View>
7595
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './block/block'
22
export * from './grid/grid'
33
export * from './list/list'
4+
export * from './root-portal/root-portal'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FC } from 'preact/compat'
2+
import React, { CSSProperties, ReactNode } from 'react'
3+
4+
interface Props {
5+
enable?: boolean
6+
style?: CSSProperties | undefined
7+
children?: ReactNode | undefined
8+
}
9+
10+
export const RootPortal: FC<Props> = ({ enable = true, style, children }: Props) => {
11+
return <div
12+
style={enable ? { position: 'fixed', width: '100%', height: '100%' } : { position: 'static' }}>
13+
{style ? <div style={style}>{children}</div> : children}
14+
</div>
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { StickyHeaderProps } from '@tarojs/components/dist/types/StickyHeader'
2+
import React, { FC } from 'react'
3+
4+
export const StickyHeader: FC<StickyHeaderProps> = ({ className, children, hidden = false }) => {
5+
6+
return <div className={className} style={{
7+
display: 'flex',
8+
position: 'sticky',
9+
left: 0,
10+
top: 0,
11+
flexDirection: 'column'
12+
}} hidden={hidden}>
13+
{children}
14+
</div>
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { StickySectionProps } from '@tarojs/components/dist/types/StickySection'
2+
import React, { FC } from 'react'
3+
4+
export const StickySection: FC<StickySectionProps> = ({ children, style, className }) => {
5+
return <div style={typeof style === 'string' ? {} : style} className={className}>{children}</div>
6+
}

packages/taro-components-mpharmony/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export { default as PullDownRefresh } from '@tarojs/components-react/dist/compon
5050
export { PullToRefresh } from '@tarojs/components/lib/react'
5151
export { Radio, RadioGroup } from '@tarojs/components/lib/react'
5252
export { RichText } from '@tarojs/components/lib/react'
53-
export { RootPortal } from '@tarojs/components/lib/react'
5453
export { RtcRoom, RtcRoomItem } from '@tarojs/components/lib/react'
5554
export { default as ScrollView } from '@tarojs/components-react/dist/components/scroll-view'
5655
export { ShareElement } from '@tarojs/components/lib/react'
@@ -69,3 +68,6 @@ export { WebView } from '@tarojs/components/lib/react'
6968
export * from './components/block/block'
7069
export * from './components/grid/grid'
7170
export * from './components/list/list'
71+
export * from './components/root-portal/root-portal'
72+
export * from './components/sticky-header/sticky-header'
73+
export * from './components/sticky-section/sticky-section'

0 commit comments

Comments
 (0)