Skip to content

Commit d0b6130

Browse files
authored
feat(slides): add support for Swiper 7 (#24190)
1 parent 579d118 commit d0b6130

File tree

7 files changed

+118
-18
lines changed

7 files changed

+118
-18
lines changed

angular/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export * from './types/ionic-lifecycle-hooks';
4343
export { IonicModule } from './ionic-module';
4444

4545
// UTILS
46-
export { IonicSafeString, getPlatforms, isPlatform, createAnimation, IonicSwiper } from '@ionic/core';
46+
export { IonicSafeString, getPlatforms, isPlatform, createAnimation, IonicSwiper, IonicSlides } from '@ionic/core';
4747

4848
// CORE TYPES
4949
export {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
export const IonicSlides = (opts: any) => {
2+
const { swiper, extendParams } = opts;
3+
const slidesParams: any = {
4+
effect: undefined,
5+
direction: 'horizontal',
6+
initialSlide: 0,
7+
loop: false,
8+
parallax: false,
9+
slidesPerView: 1,
10+
spaceBetween: 0,
11+
speed: 300,
12+
slidesPerColumn: 1,
13+
slidesPerColumnFill: 'column',
14+
slidesPerGroup: 1,
15+
centeredSlides: false,
16+
slidesOffsetBefore: 0,
17+
slidesOffsetAfter: 0,
18+
touchEventsTarget: 'container',
19+
autoplay: false,
20+
freeMode: false,
21+
freeModeMomentum: true,
22+
freeModeMomentumRatio: 1,
23+
freeModeMomentumBounce: true,
24+
freeModeMomentumBounceRatio: 1,
25+
freeModeMomentumVelocityRatio: 1,
26+
freeModeSticky: false,
27+
freeModeMinimumVelocity: 0.02,
28+
autoHeight: false,
29+
setWrapperSize: false,
30+
zoom: {
31+
maxRatio: 3,
32+
minRatio: 1,
33+
toggle: false,
34+
},
35+
touchRatio: 1,
36+
touchAngle: 45,
37+
simulateTouch: true,
38+
touchStartPreventDefault: false,
39+
shortSwipes: true,
40+
longSwipes: true,
41+
longSwipesRatio: 0.5,
42+
longSwipesMs: 300,
43+
followFinger: true,
44+
threshold: 0,
45+
touchMoveStopPropagation: true,
46+
touchReleaseOnEdges: false,
47+
iOSEdgeSwipeDetection: false,
48+
iOSEdgeSwipeThreshold: 20,
49+
resistance: true,
50+
resistanceRatio: 0.85,
51+
watchSlidesProgress: false,
52+
watchSlidesVisibility: false,
53+
preventClicks: true,
54+
preventClicksPropagation: true,
55+
slideToClickedSlide: false,
56+
loopAdditionalSlides: 0,
57+
noSwiping: true,
58+
runCallbacksOnInit: true,
59+
coverflowEffect: {
60+
rotate: 50,
61+
stretch: 0,
62+
depth: 100,
63+
modifier: 1,
64+
slideShadows: true
65+
},
66+
flipEffect: {
67+
slideShadows: true,
68+
limitRotation: true
69+
},
70+
cubeEffect: {
71+
slideShadows: true,
72+
shadow: true,
73+
shadowOffset: 20,
74+
shadowScale: 0.94
75+
},
76+
fadeEffect: {
77+
crossFade: false
78+
},
79+
a11y: {
80+
prevSlideMessage: 'Previous slide',
81+
nextSlideMessage: 'Next slide',
82+
firstSlideMessage: 'This is the first slide',
83+
lastSlideMessage: 'This is the last slide'
84+
}
85+
}
86+
87+
if (swiper.pagination) {
88+
slidesParams.pagination = {
89+
type: 'bullets',
90+
clickable: false,
91+
hideOnClick: false,
92+
}
93+
}
94+
95+
if (swiper.scrollbar) {
96+
slidesParams.scrollbar = {
97+
hide: true
98+
}
99+
}
100+
101+
extendParams(slidesParams);
102+
}

core/src/components/slides/IonicSwiper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ export const IonicSwiper = {
120120
name: 'ionic',
121121
on: {
122122
afterInit(swiper: any) {
123+
console.warn('[Deprecation Warning]: The IonicSwiper module has been deprecated in favor of the IonSlides module. This change was made to better support the Swiper 7 release. The IonicSwiper module will be removed in Ionic 7.0. See https://ionicframework.com/docs/api/slides#migration for revised migration steps.');
124+
123125
setupSwiperInIonic(swiper);
124126
}
125127
}

core/src/css/ionic-swiper.scss

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Slides
55
// --------------------------------------------------
66

7-
.swiper-container {
7+
.swiper {
88

99
// These values are the same for iOS and MD
1010
// We just do not add a .md or .ios class beforehand
@@ -33,56 +33,49 @@
3333
// Pagination Bullets
3434
// --------------------------------------------------
3535

36-
.swiper-pagination-bullet {
36+
.swiper .swiper-pagination-bullet {
3737
background: var(--bullet-background);
3838
}
3939

40-
.swiper-pagination-bullet-active {
40+
.swiper .swiper-pagination-bullet-active {
4141
background: var(--bullet-background-active);
4242
}
4343

4444

4545
// Pagination Progress Bar
4646
// --------------------------------------------------
4747

48-
.swiper-pagination-progressbar {
48+
.swiper .swiper-pagination-progressbar {
4949
background: var(--progress-bar-background);
5050
}
5151

52-
.swiper-pagination-progressbar .swiper-pagination-progressbar-fill {
52+
.swiper .swiper-pagination-progressbar .swiper-pagination-progressbar-fill {
5353
background: var(--progress-bar-background-active);
5454
}
5555

5656
// Scrollbar
5757
// --------------------------------------------------
5858

59-
.swiper-scrollbar {
59+
.swiper .swiper-scrollbar {
6060
background: var(--scroll-bar-background);
6161
}
6262

63-
.swiper-scrollbar-drag {
63+
.swiper .swiper-scrollbar-drag {
6464
background: var(--scroll-bar-background-active);
6565
}
6666

6767
// Slide
6868
// --------------------------------------------------
6969

70-
ion-slide {
71-
display: block;
72-
73-
width: 100%;
74-
height: 100%;
75-
}
76-
77-
.slide-zoom {
70+
.swiper .slide-zoom {
7871
display: block;
7972

8073
width: 100%;
8174

8275
text-align: center;
8376
}
8477

85-
.swiper-slide {
78+
.swiper .swiper-slide {
8679

8780
// Center slide text vertically
8881
display: flex;
@@ -101,7 +94,7 @@ ion-slide {
10194
box-sizing: border-box;
10295
}
10396

104-
.swiper-slide img {
97+
.swiper .swiper-slide img {
10598
width: auto;
10699
max-width: 100%;
107100
height: auto;

core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export { LIFECYCLE_WILL_ENTER, LIFECYCLE_DID_ENTER, LIFECYCLE_WILL_LEAVE, LIFECY
1414
export { menuController } from './utils/menu-controller';
1515
export { alertController, actionSheetController, modalController, loadingController, pickerController, popoverController, toastController } from './utils/overlays';
1616
export { IonicSwiper } from './components/slides/IonicSwiper';
17+
export { IonicSlides } from './components/slides/IonicSlides';

packages/react/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
NavComponentWithProps,
3535
setupConfig,
3636
IonicSwiper,
37+
IonicSlides,
3738

3839
SpinnerTypes,
3940

packages/vue/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export {
7474

7575
// Swiper
7676
IonicSwiper,
77+
IonicSlides,
7778

7879
SpinnerTypes,
7980

0 commit comments

Comments
 (0)