mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 14:28:51 +00:00
[samples_index] Fix carousel edge cases and make mobile responsive (#608)
* Fix carousel ui issues * Update carousel to be mobile responsive
This commit is contained in:
committed by
GitHub
parent
6b561158b1
commit
d1b054cb02
@@ -14,13 +14,30 @@ class Carousel {
|
|||||||
|
|
||||||
Element prevSlide, currentSlide, nextSlide;
|
Element prevSlide, currentSlide, nextSlide;
|
||||||
|
|
||||||
|
num x0;
|
||||||
|
bool touched = false;
|
||||||
|
|
||||||
Carousel.init({this.withArrowKeyControl = false}) {
|
Carousel.init({this.withArrowKeyControl = false}) {
|
||||||
lastSlideIndex = slides.length - 1;
|
lastSlideIndex = slides.length - 1;
|
||||||
currentSlideIndex = -1;
|
currentSlideIndex = -1;
|
||||||
|
|
||||||
|
// Remove container empty space when no images are available
|
||||||
|
if (lastSlideIndex == -1) {
|
||||||
|
container.classes.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip carousel decoration when only one image is available
|
||||||
|
if (lastSlideIndex == 0) {
|
||||||
|
currentSlide = slides[currentSlideIndex + 1];
|
||||||
|
currentSlide.classes.add('active');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_hideSlides();
|
_hideSlides();
|
||||||
_initBullets();
|
_initBullets();
|
||||||
_initArrows();
|
_initArrows();
|
||||||
|
_initGestureListener();
|
||||||
|
|
||||||
if (withArrowKeyControl) {
|
if (withArrowKeyControl) {
|
||||||
_initArrowKeyControl();
|
_initArrowKeyControl();
|
||||||
@@ -71,6 +88,30 @@ class Carousel {
|
|||||||
container.append(nextArrow);
|
container.append(nextArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _touchStartListener(TouchEvent e) {
|
||||||
|
x0 = e.changedTouches.first.client.x;
|
||||||
|
touched = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _touchEndListener(TouchEvent e) {
|
||||||
|
if (touched) {
|
||||||
|
int dx = e.changedTouches.first.client.x - x0;
|
||||||
|
|
||||||
|
// dx==0 case is ignored
|
||||||
|
if (dx > 0 && currentSlideIndex > 0) {
|
||||||
|
_slideLeft();
|
||||||
|
} else if (dx < 0 && currentSlideIndex < lastSlideIndex) {
|
||||||
|
_slideRight();
|
||||||
|
}
|
||||||
|
touched = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _initGestureListener() {
|
||||||
|
container.onTouchStart.listen(_touchStartListener);
|
||||||
|
container.onTouchEnd.listen(_touchEndListener);
|
||||||
|
}
|
||||||
|
|
||||||
void _updateBullets() {
|
void _updateBullets() {
|
||||||
final bullets =
|
final bullets =
|
||||||
querySelector('.bullet-container').querySelectorAll('.bullet');
|
querySelector('.bullet-container').querySelectorAll('.bullet');
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ $mode: cubic-bezier(0.17, 0.67, 0.55, 1.43);
|
|||||||
html, body {
|
html, body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -140,8 +144,6 @@ a {
|
|||||||
color: white;
|
color: white;
|
||||||
padding: 16px 125px 16px 125px;
|
padding: 16px 125px 16px 125px;
|
||||||
margin-bottom: 48px;
|
margin-bottom: 48px;
|
||||||
|
|
||||||
|
|
||||||
@media screen and (max-width: $mobile-width) {
|
@media screen and (max-width: $mobile-width) {
|
||||||
padding: 8px 16px 8px 16px;
|
padding: 8px 16px 8px 16px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
@@ -220,7 +222,6 @@ a {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: start;
|
align-items: start;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
|
|
||||||
@media screen and (max-width: $mobile-width) {
|
@media screen and (max-width: $mobile-width) {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
@@ -233,32 +234,6 @@ a {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.screenshots {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
height: 360px;
|
|
||||||
overflow-x: scroll;
|
|
||||||
margin: 48px 0 48px 0;
|
|
||||||
|
|
||||||
@media screen and (max-width: $mobile-width) {
|
|
||||||
height: 240px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
flex-wrap: nowrap;
|
|
||||||
overflow-x: scroll;
|
|
||||||
img {
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
border-radius: 8px;
|
|
||||||
margin: 0 8px 0 8px;
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.index-header {
|
.index-header {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
@@ -428,12 +403,13 @@ a {
|
|||||||
// Carousel Container
|
// Carousel Container
|
||||||
.slider-container {
|
.slider-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 0 auto;
|
margin: -80px auto -60px auto;
|
||||||
width: 800px;
|
width: 800px;
|
||||||
height: 600px;
|
height: 600px;
|
||||||
max-width: 100%;
|
max-width: 95%;
|
||||||
margin-top: -80px;
|
@media screen and (max-width: $mobile-width) {
|
||||||
margin-bottom: -60px;
|
margin: -80px 4px -60px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.bullet-container {
|
.bullet-container {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -471,6 +447,9 @@ a {
|
|||||||
width: 70%;
|
width: 70%;
|
||||||
height: 60%;
|
height: 60%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
width: 100%
|
||||||
|
}
|
||||||
|
|
||||||
.slider-single {
|
.slider-single {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -497,6 +476,10 @@ a {
|
|||||||
.slider-single-image {
|
.slider-single-image {
|
||||||
transform: translateX(-50%) scale(0);
|
transform: translateX(-50%) scale(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.prev {
|
&.prev {
|
||||||
@@ -521,6 +504,10 @@ a {
|
|||||||
.slider-single-image {
|
.slider-single-image {
|
||||||
transform: translateX(50%) scale(0);
|
transform: translateX(50%) scale(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
@@ -545,6 +532,9 @@ a {
|
|||||||
padding: 20px 20px;
|
padding: 20px 20px;
|
||||||
margin-right: -2px;
|
margin-right: -2px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.slider-right {
|
.slider-right {
|
||||||
@@ -558,6 +548,9 @@ a {
|
|||||||
padding: 20px 20px;
|
padding: 20px 20px;
|
||||||
margin-left: -2px;
|
margin-left: -2px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@media screen and (max-width: $mobile-width) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
|
|||||||
Reference in New Issue
Block a user