@lynx-example/lynx-ui-swiper 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Basic/index.tsx +109 -0
- package/Basic/styles.css +49 -0
- package/BasicDynamic/index.tsx +130 -0
- package/BasicDynamic/styles.css +47 -0
- package/BasicUpdateSize/index.tsx +131 -0
- package/BasicUpdateSize/styles.css +47 -0
- package/Bounces/index.tsx +73 -0
- package/Bounces/styles.css +41 -0
- package/CHANGELOG.md +15 -0
- package/Common/Button/index.tsx +48 -0
- package/Common/Button/styles.css +41 -0
- package/Common/Card/index.tsx +21 -0
- package/Common/Card/styles.css +21 -0
- package/Common/Indicator/index.tsx +24 -0
- package/Common/Indicator/styles.css +21 -0
- package/Custom/index.tsx +87 -0
- package/Custom/styles.css +47 -0
- package/CustomScale/index.tsx +116 -0
- package/CustomScale/styles.css +41 -0
- package/CustomTinder/Card.tsx +24 -0
- package/CustomTinder/index.tsx +111 -0
- package/CustomTinder/styles.css +61 -0
- package/DifferentHeight/Button.tsx +33 -0
- package/DifferentHeight/index.tsx +95 -0
- package/DifferentHeight/styles.css +50 -0
- package/Direction/index.tsx +127 -0
- package/Direction/styles.css +41 -0
- package/EmptyDataBug/index.tsx +371 -0
- package/EmptyDataBug/styles.css +75 -0
- package/Indicator/index.tsx +67 -0
- package/Indicator/styles.css +41 -0
- package/Lazy/index.tsx +83 -0
- package/Lazy/styles.css +41 -0
- package/Loop/index.tsx +77 -0
- package/Loop/styles.css +41 -0
- package/RTL/Button.tsx +33 -0
- package/RTL/index.tsx +133 -0
- package/RTL/styles.css +41 -0
- package/RTLCustom/index.tsx +115 -0
- package/RTLCustom/styles.css +41 -0
- package/RTLLoop/Button.tsx +33 -0
- package/RTLLoop/index.tsx +116 -0
- package/RTLLoop/styles.css +41 -0
- package/RTLLoopLynxRTL/Button.tsx +33 -0
- package/RTLLoopLynxRTL/index.tsx +116 -0
- package/RTLLoopLynxRTL/styles.css +41 -0
- package/WithGap/Button.tsx +33 -0
- package/WithGap/index.tsx +118 -0
- package/WithGap/styles.css +47 -0
- package/dist/SwiperBasic.lynx.bundle +0 -0
- package/dist/SwiperBasic.web.bundle +1 -1
- package/dist/SwiperBasicDynamic.lynx.bundle +0 -0
- package/dist/SwiperBasicDynamic.web.bundle +1 -1
- package/dist/SwiperBasicUpdateSize.lynx.bundle +0 -0
- package/dist/SwiperBasicUpdateSize.web.bundle +1 -1
- package/dist/SwiperCustomTinder.lynx.bundle +0 -0
- package/dist/SwiperCustomTinder.web.bundle +1 -1
- package/dist/SwiperDifferentHeight.lynx.bundle +0 -0
- package/dist/SwiperDifferentHeight.web.bundle +1 -1
- package/dist/SwiperEmptyDataBug.lynx.bundle +0 -0
- package/dist/SwiperEmptyDataBug.web.bundle +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { root, useRef } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Swiper,
|
|
9
|
+
SwiperItem,
|
|
10
|
+
interpolate,
|
|
11
|
+
interpolateJS,
|
|
12
|
+
} from '@lynx-js/lynx-ui'
|
|
13
|
+
import type { SwiperRef } from '@lynx-js/lynx-ui'
|
|
14
|
+
|
|
15
|
+
import './styles.css'
|
|
16
|
+
|
|
17
|
+
const colorsArr: string[] = ['red', 'green', 'yellow', 'purple']
|
|
18
|
+
|
|
19
|
+
const ITEM_WIDTH = 250
|
|
20
|
+
|
|
21
|
+
function customAnimation(value: number, _index: number) {
|
|
22
|
+
'main thread'
|
|
23
|
+
|
|
24
|
+
const RTL = true
|
|
25
|
+
const sign = RTL ? -1 : 1
|
|
26
|
+
|
|
27
|
+
const scale = interpolate(value, [-1, 0, 1], [0.8, 1, 0.8])
|
|
28
|
+
|
|
29
|
+
const centerOffset = ((lynx.__globalProps.screenWidth
|
|
30
|
+
?? SystemInfo.pixelWidth / SystemInfo.pixelRatio) - ITEM_WIDTH) / 2
|
|
31
|
+
const translateX = interpolate(value, [-1, 0, 1], [
|
|
32
|
+
-ITEM_WIDTH + centerOffset,
|
|
33
|
+
centerOffset,
|
|
34
|
+
ITEM_WIDTH + centerOffset,
|
|
35
|
+
], 'extend')
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
transform: `translateX(${sign * translateX}px) scale(${scale})`,
|
|
39
|
+
'transform-origin': 'center',
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function customAnimationFirstScreen(value: number, _index: number) {
|
|
44
|
+
const RTL = true
|
|
45
|
+
const sign = RTL ? -1 : 1
|
|
46
|
+
|
|
47
|
+
const scale = interpolateJS(value, [-1, 0, 1], [0.8, 1, 0.8])
|
|
48
|
+
|
|
49
|
+
const centerOffset = ((lynx.__globalProps.screenWidth
|
|
50
|
+
?? SystemInfo.pixelWidth / SystemInfo.pixelRatio) - ITEM_WIDTH) / 2
|
|
51
|
+
const translateX = interpolateJS(value, [-1, 0, 1], [
|
|
52
|
+
-ITEM_WIDTH + centerOffset,
|
|
53
|
+
centerOffset,
|
|
54
|
+
ITEM_WIDTH + centerOffset,
|
|
55
|
+
], 'extend')
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
transform: `translateX(${sign * translateX}px) scale(${scale})`,
|
|
59
|
+
'transform-origin': 'center',
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function SwiperEntry(): JSX.Element {
|
|
64
|
+
const swiperRef = useRef<SwiperRef>(null)
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<view id='container'>
|
|
68
|
+
<Swiper
|
|
69
|
+
ref={swiperRef}
|
|
70
|
+
data={colorsArr}
|
|
71
|
+
itemWidth={ITEM_WIDTH}
|
|
72
|
+
itemHeight={200}
|
|
73
|
+
duration={500}
|
|
74
|
+
initialIndex={0}
|
|
75
|
+
mode='custom'
|
|
76
|
+
modeConfig={{
|
|
77
|
+
align: 'center',
|
|
78
|
+
}}
|
|
79
|
+
RTL={true}
|
|
80
|
+
main-thread:customAnimation={customAnimation}
|
|
81
|
+
customAnimationFirstScreen={customAnimationFirstScreen}
|
|
82
|
+
>
|
|
83
|
+
{({ item, index, realIndex }) => (
|
|
84
|
+
<SwiperItem index={index} key={realIndex} realIndex={realIndex}>
|
|
85
|
+
<view
|
|
86
|
+
class='block-view'
|
|
87
|
+
style={{
|
|
88
|
+
width: '100%',
|
|
89
|
+
height: '100%',
|
|
90
|
+
backgroundColor: item,
|
|
91
|
+
display: 'flex',
|
|
92
|
+
justifyContent: 'center',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<view
|
|
97
|
+
style={{
|
|
98
|
+
backgroundColor: 'white',
|
|
99
|
+
width: '4px',
|
|
100
|
+
height: '4px',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
</view>
|
|
104
|
+
</view>
|
|
105
|
+
<text class='image-text'>Number.{index}</text>
|
|
106
|
+
</SwiperItem>
|
|
107
|
+
)}
|
|
108
|
+
</Swiper>
|
|
109
|
+
</view>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
root.render(<SwiperEntry />)
|
|
114
|
+
|
|
115
|
+
export default SwiperEntry
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.image {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.image-text {
|
|
7
|
+
position: absolute;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.container {
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.title-container {
|
|
16
|
+
margin-top: 10px;
|
|
17
|
+
margin-bottom: 5px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.title-text {
|
|
21
|
+
font-size: 16px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.button {
|
|
25
|
+
border: 1px solid;
|
|
26
|
+
border-radius: 4px;
|
|
27
|
+
width: 150px;
|
|
28
|
+
background-color: red;
|
|
29
|
+
margin: 4px 8px;
|
|
30
|
+
padding: 4px 8px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.button-text {
|
|
34
|
+
color: white;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.operation {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import './styles.css'
|
|
6
|
+
import { Button as ButtonInner } from '@lynx-js/lynx-ui'
|
|
7
|
+
|
|
8
|
+
const ButtonStyle = {
|
|
9
|
+
border: '1px solid',
|
|
10
|
+
'border-radius': '4px',
|
|
11
|
+
width: '150px',
|
|
12
|
+
'background-color': 'red',
|
|
13
|
+
margin: '4px 8px',
|
|
14
|
+
padding: '4px 8px',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ButtonTextStyle = {
|
|
18
|
+
color: 'white',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Button(props: {
|
|
22
|
+
onClick: () => void
|
|
23
|
+
text: string
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<ButtonInner
|
|
27
|
+
style={ButtonStyle}
|
|
28
|
+
onClick={props.onClick}
|
|
29
|
+
>
|
|
30
|
+
<text style={ButtonTextStyle}>{props.text}</text>
|
|
31
|
+
</ButtonInner>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { root, useRef, useState } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
|
|
8
|
+
import type { SwiperRef } from '@lynx-js/lynx-ui'
|
|
9
|
+
|
|
10
|
+
import './styles.css'
|
|
11
|
+
|
|
12
|
+
import { Button } from './Button'
|
|
13
|
+
|
|
14
|
+
const colorsArr: string[] = [
|
|
15
|
+
'red',
|
|
16
|
+
'green',
|
|
17
|
+
'yellow',
|
|
18
|
+
'purple',
|
|
19
|
+
'lightblue',
|
|
20
|
+
'lightgreen',
|
|
21
|
+
'lightyellow',
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const itemWidths = [250, 350, 400]
|
|
25
|
+
const alignArr: ['start', 'center', 'end'] = ['start', 'center', 'end']
|
|
26
|
+
|
|
27
|
+
function SwiperEntry(): JSX.Element {
|
|
28
|
+
const [itemWidthsIndex, setItemWidthsIndex] = useState<number>(0)
|
|
29
|
+
const [alignIndex, setAlignIndex] = useState<number>(0)
|
|
30
|
+
const [currentIndex, setCurrentIndex] = useState<number>(0)
|
|
31
|
+
const swiperRef = useRef<SwiperRef>(null)
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<view id='container'>
|
|
35
|
+
<Swiper
|
|
36
|
+
ref={swiperRef}
|
|
37
|
+
data={colorsArr}
|
|
38
|
+
itemWidth={itemWidths[itemWidthsIndex] ?? 0}
|
|
39
|
+
itemHeight={200}
|
|
40
|
+
duration={500}
|
|
41
|
+
initialIndex={0}
|
|
42
|
+
onChange={setCurrentIndex}
|
|
43
|
+
mode='normal'
|
|
44
|
+
modeConfig={{
|
|
45
|
+
align: alignArr[alignIndex] ?? 'start',
|
|
46
|
+
spaceBetween: 8,
|
|
47
|
+
}}
|
|
48
|
+
RTL={true}
|
|
49
|
+
loop={true}
|
|
50
|
+
>
|
|
51
|
+
{({ item, index, realIndex }) => (
|
|
52
|
+
<SwiperItem index={index} key={realIndex} realIndex={realIndex}>
|
|
53
|
+
<view
|
|
54
|
+
class='block-view'
|
|
55
|
+
style={{
|
|
56
|
+
width: '100%',
|
|
57
|
+
height: '100%',
|
|
58
|
+
backgroundColor: item,
|
|
59
|
+
display: 'flex',
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
alignItems: 'center',
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<view
|
|
65
|
+
style={{
|
|
66
|
+
backgroundColor: 'white',
|
|
67
|
+
width: '4px',
|
|
68
|
+
height: '4px',
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
</view>
|
|
72
|
+
</view>
|
|
73
|
+
<text class='image-text'>Number.{index}</text>
|
|
74
|
+
</SwiperItem>
|
|
75
|
+
)}
|
|
76
|
+
</Swiper>
|
|
77
|
+
<view class='operation'>
|
|
78
|
+
<view class='block'>
|
|
79
|
+
<text>Current Index: {currentIndex}</text>
|
|
80
|
+
</view>
|
|
81
|
+
<Button
|
|
82
|
+
onClick={() => {
|
|
83
|
+
swiperRef.current?.swipePrev()
|
|
84
|
+
}}
|
|
85
|
+
text='SwipePrev'
|
|
86
|
+
>
|
|
87
|
+
</Button>
|
|
88
|
+
<Button
|
|
89
|
+
onClick={() => {
|
|
90
|
+
swiperRef.current?.swipeNext()
|
|
91
|
+
}}
|
|
92
|
+
text='SwipeNext'
|
|
93
|
+
>
|
|
94
|
+
</Button>
|
|
95
|
+
<Button
|
|
96
|
+
onClick={() => {
|
|
97
|
+
setItemWidthsIndex(prev => (prev + 1) % itemWidths.length)
|
|
98
|
+
}}
|
|
99
|
+
text={`itemWidth: ${itemWidths[itemWidthsIndex]}`}
|
|
100
|
+
>
|
|
101
|
+
</Button>
|
|
102
|
+
<Button
|
|
103
|
+
onClick={() => {
|
|
104
|
+
setAlignIndex(prev => (prev + 1) % itemWidths.length)
|
|
105
|
+
}}
|
|
106
|
+
text={`alignType: ${alignArr[alignIndex]}`}
|
|
107
|
+
>
|
|
108
|
+
</Button>
|
|
109
|
+
</view>
|
|
110
|
+
</view>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
root.render(<SwiperEntry />)
|
|
115
|
+
|
|
116
|
+
export default SwiperEntry
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.image {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.image-text {
|
|
7
|
+
position: absolute;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.container {
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.title-container {
|
|
16
|
+
margin-top: 10px;
|
|
17
|
+
margin-bottom: 5px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.title-text {
|
|
21
|
+
font-size: 16px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.button {
|
|
25
|
+
border: 1px solid;
|
|
26
|
+
border-radius: 4px;
|
|
27
|
+
width: 150px;
|
|
28
|
+
background-color: red;
|
|
29
|
+
margin: 4px 8px;
|
|
30
|
+
padding: 4px 8px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.button-text {
|
|
34
|
+
color: white;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.operation {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import './styles.css'
|
|
6
|
+
import { Button as ButtonInner } from '@lynx-js/lynx-ui'
|
|
7
|
+
|
|
8
|
+
const ButtonStyle = {
|
|
9
|
+
border: '1px solid',
|
|
10
|
+
'border-radius': '4px',
|
|
11
|
+
width: '150px',
|
|
12
|
+
'background-color': 'red',
|
|
13
|
+
margin: '4px 8px',
|
|
14
|
+
padding: '4px 8px',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ButtonTextStyle = {
|
|
18
|
+
color: 'white',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Button(props: {
|
|
22
|
+
onClick: () => void
|
|
23
|
+
text: string
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<ButtonInner
|
|
27
|
+
style={ButtonStyle}
|
|
28
|
+
onClick={props.onClick}
|
|
29
|
+
>
|
|
30
|
+
<text style={ButtonTextStyle}>{props.text}</text>
|
|
31
|
+
</ButtonInner>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { root, useRef, useState } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
|
|
8
|
+
import type { SwiperRef } from '@lynx-js/lynx-ui'
|
|
9
|
+
|
|
10
|
+
import './styles.css'
|
|
11
|
+
|
|
12
|
+
import { Button } from './Button'
|
|
13
|
+
|
|
14
|
+
const colorsArr: string[] = [
|
|
15
|
+
'red',
|
|
16
|
+
'green',
|
|
17
|
+
'yellow',
|
|
18
|
+
'purple',
|
|
19
|
+
'lightblue',
|
|
20
|
+
'lightgreen',
|
|
21
|
+
'lightyellow',
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const itemWidths = [250, 350, 400]
|
|
25
|
+
const alignArr: ['start', 'center', 'end'] = ['start', 'center', 'end']
|
|
26
|
+
|
|
27
|
+
function SwiperEntry(): JSX.Element {
|
|
28
|
+
const [itemWidthsIndex, setItemWidthsIndex] = useState<number>(0)
|
|
29
|
+
const [alignIndex, setAlignIndex] = useState<number>(0)
|
|
30
|
+
const [currentIndex, setCurrentIndex] = useState<number>(0)
|
|
31
|
+
const swiperRef = useRef<SwiperRef>(null)
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<view id='container'>
|
|
35
|
+
<Swiper
|
|
36
|
+
ref={swiperRef}
|
|
37
|
+
data={colorsArr}
|
|
38
|
+
itemWidth={itemWidths[itemWidthsIndex] ?? 0}
|
|
39
|
+
itemHeight={200}
|
|
40
|
+
duration={500}
|
|
41
|
+
initialIndex={0}
|
|
42
|
+
onChange={setCurrentIndex}
|
|
43
|
+
mode='normal'
|
|
44
|
+
modeConfig={{
|
|
45
|
+
align: alignArr[alignIndex] ?? 'start',
|
|
46
|
+
spaceBetween: 8,
|
|
47
|
+
}}
|
|
48
|
+
RTL={'lynx-rtl'}
|
|
49
|
+
loop={true}
|
|
50
|
+
>
|
|
51
|
+
{({ item, index, realIndex }) => (
|
|
52
|
+
<SwiperItem index={index} key={realIndex} realIndex={realIndex}>
|
|
53
|
+
<view
|
|
54
|
+
class='block-view'
|
|
55
|
+
style={{
|
|
56
|
+
width: '100%',
|
|
57
|
+
height: '100%',
|
|
58
|
+
backgroundColor: item,
|
|
59
|
+
display: 'flex',
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
alignItems: 'center',
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<view
|
|
65
|
+
style={{
|
|
66
|
+
backgroundColor: 'white',
|
|
67
|
+
width: '4px',
|
|
68
|
+
height: '4px',
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
</view>
|
|
72
|
+
</view>
|
|
73
|
+
<text class='image-text'>Number.{index}</text>
|
|
74
|
+
</SwiperItem>
|
|
75
|
+
)}
|
|
76
|
+
</Swiper>
|
|
77
|
+
<view class='operation'>
|
|
78
|
+
<view class='block'>
|
|
79
|
+
<text>Current Index: {currentIndex}</text>
|
|
80
|
+
</view>
|
|
81
|
+
<Button
|
|
82
|
+
onClick={() => {
|
|
83
|
+
swiperRef.current?.swipePrev()
|
|
84
|
+
}}
|
|
85
|
+
text='SwipePrev'
|
|
86
|
+
>
|
|
87
|
+
</Button>
|
|
88
|
+
<Button
|
|
89
|
+
onClick={() => {
|
|
90
|
+
swiperRef.current?.swipeNext()
|
|
91
|
+
}}
|
|
92
|
+
text='SwipeNext'
|
|
93
|
+
>
|
|
94
|
+
</Button>
|
|
95
|
+
<Button
|
|
96
|
+
onClick={() => {
|
|
97
|
+
setItemWidthsIndex(prev => (prev + 1) % itemWidths.length)
|
|
98
|
+
}}
|
|
99
|
+
text={`itemWidth: ${itemWidths[itemWidthsIndex]}`}
|
|
100
|
+
>
|
|
101
|
+
</Button>
|
|
102
|
+
<Button
|
|
103
|
+
onClick={() => {
|
|
104
|
+
setAlignIndex(prev => (prev + 1) % itemWidths.length)
|
|
105
|
+
}}
|
|
106
|
+
text={`alignType: ${alignArr[alignIndex]}`}
|
|
107
|
+
>
|
|
108
|
+
</Button>
|
|
109
|
+
</view>
|
|
110
|
+
</view>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
root.render(<SwiperEntry />)
|
|
115
|
+
|
|
116
|
+
export default SwiperEntry
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.image {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.image-text {
|
|
7
|
+
position: absolute;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.container {
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.title-container {
|
|
16
|
+
margin-top: 10px;
|
|
17
|
+
margin-bottom: 5px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.title-text {
|
|
21
|
+
font-size: 16px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.button {
|
|
25
|
+
border: 1px solid;
|
|
26
|
+
border-radius: 4px;
|
|
27
|
+
width: 150px;
|
|
28
|
+
background-color: red;
|
|
29
|
+
margin: 4px 8px;
|
|
30
|
+
padding: 4px 8px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.button-text {
|
|
34
|
+
color: white;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.operation {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import './styles.css'
|
|
6
|
+
import { Button as ButtonInner } from '@lynx-js/lynx-ui'
|
|
7
|
+
|
|
8
|
+
const ButtonStyle = {
|
|
9
|
+
border: '1px solid',
|
|
10
|
+
'border-radius': '4px',
|
|
11
|
+
width: '150px',
|
|
12
|
+
'background-color': 'red',
|
|
13
|
+
margin: '4px 8px',
|
|
14
|
+
padding: '4px 8px',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ButtonTextStyle = {
|
|
18
|
+
color: 'white',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Button(props: {
|
|
22
|
+
onClick: () => void
|
|
23
|
+
text: string
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<ButtonInner
|
|
27
|
+
style={ButtonStyle}
|
|
28
|
+
onClick={props.onClick}
|
|
29
|
+
>
|
|
30
|
+
<text style={ButtonTextStyle}>{props.text}</text>
|
|
31
|
+
</ButtonInner>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { root, useRef, useState } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { Swiper, SwiperItem } from '@lynx-js/lynx-ui'
|
|
8
|
+
import type { SwiperRef } from '@lynx-js/lynx-ui'
|
|
9
|
+
|
|
10
|
+
import './styles.css'
|
|
11
|
+
|
|
12
|
+
import { Button } from './Button'
|
|
13
|
+
|
|
14
|
+
const DEFAULT_COLORS_ARR: string[] = [
|
|
15
|
+
'red',
|
|
16
|
+
'green',
|
|
17
|
+
'yellow',
|
|
18
|
+
'purple',
|
|
19
|
+
'lightgreen',
|
|
20
|
+
'lightyellow',
|
|
21
|
+
'lightblue',
|
|
22
|
+
'gray',
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
const itemWidths = [250, 350, 400]
|
|
26
|
+
const alignArr: ['start', 'center', 'end'] = ['start', 'center', 'end']
|
|
27
|
+
|
|
28
|
+
function SwiperEntry(): JSX.Element {
|
|
29
|
+
const [itemWidthsIndex, setItemWidthsIndex] = useState<number>(0)
|
|
30
|
+
const [alignIndex, setAlignIndex] = useState<number>(0)
|
|
31
|
+
const [currentIndex, setCurrentIndex] = useState<number>(0)
|
|
32
|
+
const swiperRef = useRef<SwiperRef>(null)
|
|
33
|
+
const [colorsArr, _setColorsArr] = useState<string[]>(DEFAULT_COLORS_ARR)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<view id='container'>
|
|
37
|
+
<Swiper
|
|
38
|
+
ref={swiperRef}
|
|
39
|
+
data={colorsArr}
|
|
40
|
+
itemWidth={itemWidths[itemWidthsIndex] ?? 0}
|
|
41
|
+
itemHeight={200}
|
|
42
|
+
duration={500}
|
|
43
|
+
initialIndex={0}
|
|
44
|
+
onChange={setCurrentIndex}
|
|
45
|
+
mode='normal'
|
|
46
|
+
loop={false}
|
|
47
|
+
autoPlay={true}
|
|
48
|
+
modeConfig={{
|
|
49
|
+
align: alignArr[alignIndex] ?? 'start',
|
|
50
|
+
spaceBetween: 10,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{({ item, index, realIndex }) => (
|
|
54
|
+
<SwiperItem index={index} key={realIndex} realIndex={realIndex}>
|
|
55
|
+
<view
|
|
56
|
+
class='block-view'
|
|
57
|
+
style={{
|
|
58
|
+
width: '100%',
|
|
59
|
+
height: '100%',
|
|
60
|
+
backgroundColor: item,
|
|
61
|
+
display: 'flex',
|
|
62
|
+
justifyContent: 'center',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<view
|
|
67
|
+
style={{
|
|
68
|
+
backgroundColor: 'white',
|
|
69
|
+
width: '4px',
|
|
70
|
+
height: '4px',
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
</view>
|
|
74
|
+
</view>
|
|
75
|
+
<text class='image-text'>Number.{index}</text>
|
|
76
|
+
</SwiperItem>
|
|
77
|
+
)}
|
|
78
|
+
</Swiper>
|
|
79
|
+
<view class='operation'>
|
|
80
|
+
<view class='block'>
|
|
81
|
+
<text>Current Index: {currentIndex}</text>
|
|
82
|
+
</view>
|
|
83
|
+
<Button
|
|
84
|
+
onClick={() => {
|
|
85
|
+
swiperRef.current?.swipePrev()
|
|
86
|
+
}}
|
|
87
|
+
text='SwipePrev'
|
|
88
|
+
>
|
|
89
|
+
</Button>
|
|
90
|
+
<Button
|
|
91
|
+
onClick={() => {
|
|
92
|
+
swiperRef.current?.swipeNext()
|
|
93
|
+
}}
|
|
94
|
+
text='SwipeNext'
|
|
95
|
+
>
|
|
96
|
+
</Button>
|
|
97
|
+
<Button
|
|
98
|
+
onClick={() => {
|
|
99
|
+
setItemWidthsIndex(prev => (prev + 1) % itemWidths.length)
|
|
100
|
+
}}
|
|
101
|
+
text={`itemWidth: ${itemWidths[itemWidthsIndex]}`}
|
|
102
|
+
>
|
|
103
|
+
</Button>
|
|
104
|
+
<Button
|
|
105
|
+
onClick={() => {
|
|
106
|
+
setAlignIndex(prev => (prev + 1) % itemWidths.length)
|
|
107
|
+
}}
|
|
108
|
+
text={`alignType: ${alignArr[alignIndex]}`}
|
|
109
|
+
>
|
|
110
|
+
</Button>
|
|
111
|
+
</view>
|
|
112
|
+
</view>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
root.render(<SwiperEntry />)
|
|
117
|
+
|
|
118
|
+
export default SwiperEntry
|