Skip to content

Commit

Permalink
appinio_swiper - version 2.1.0
Browse files Browse the repository at this point in the history
* cleanup and notify on position change

* finished?

* formatting change

* added comments to the example

* moved documentation

* added explanation to rotation point

* fix angle and halve max angle to compensate

* remove plural from cardsBuilder

* switched all controller getters to nullable instead of throw

* fixed animation interruption bugs, copied new swiper version content over

* fix

* fix

* fix: onEnd

* fix: allowUnswipe

* Fix: canunswipe once

* fix: onunswipe

* onUnSwipe

* fix: onSwipeCancelled

* refactor: readme

* readme

* appinio_swiper - version 2.1.0

---------

Co-authored-by: Casey Rogers <[email protected]>
Co-authored-by: Bilal <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 579b6e4 commit bd9f10e
Show file tree
Hide file tree
Showing 18 changed files with 1,203 additions and 908 deletions.
9 changes: 9 additions & 0 deletions packages/appinio_swiper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
## [2.1.0] - 2023.11.21
* Features:
- The controller now exposes all relevant card state (index, card offset+rotation, etc).
- The controller now has animateTo to arbitrarily animate the top card’s offset.
- Added onSwipeEnd, onSwipeBegin and onCardPositionChanged methods to give the swipe information.
- Added SwiperActivity class to give more information during card swipe.
- Better documentation, linting and code formatting.

## [2.0.3] - 2023.08.23
* Features:
- Custom background card spacing.
- onSwipeCancelled event.



## [2.0.2] - 2023.06.19
* Features:
- You can pass any combination of SwipeOptions.
Expand Down
101 changes: 73 additions & 28 deletions packages/appinio_swiper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,69 @@ We build this package because we wanted to:
- set swipe options and restrict horizontal or vertical swipe.
- set loop for infinite scroll
- update the list of cards between swipes.
- Check in which direction the card is being swiped and modify your widget accordingly.
- Check in which direction the card is being swiped and modify your widget accordingly.- We can have any number of
background cards.
- Pass any combination of swipe options.
- NEW - check when user is swiping card back before reaching the threshold value.
- NEW - Get current card index, offset and rotation
- NEW - Programmatically animate card swipe.
- NEW - We can have any number of background cards.
- NEW - Pass any combination of swipe options.


## ❗NEW Features ❗

### Animate the top card.

Now you can arbitrarily animate the position of the top card using ```AppinioSwiperController.animatTo```.

### Listen to the card offset and rotation.

Now you can track the offset and rotation of the top card by listening to the ```AppinioSwiperController```.

### Know when user is coming back without completely swiping the card.

Now you can track if user is swiping the card back to the center with the ```CancelSwipe``` ```SwiperActivity```.

### Space background cards as per your requirement.
Now you can decide the spacing between the background cards and can also hide them by giving ```cardsSpacing = 0```.

Now you can decide the spacing between the background cards and can also hide them by
giving ```backgroundCardOffset = Offset.zero```.

### onSwipeCancelEvent.
We have added onSwipeCancel event to check if the card swiped completely or if the swipe got canceled in the middle.

We have added onSwipeCancel event to check if the card swiped completely or if the swipe got canceled in the middle.

### Add different combinations for swipe options.
Now you can provide any combination of swipe options. For example: The user can swipe to the left and bottom but not top, or any possible combination.

Now you can provide any combination of swipe options. For example: The user can swipe to the left and bottom but not
top, or any possible combination.

### Show any number of background cards.

Now you can decide how many background cards you want to show.

### Listen to card swipes

Now you can check in which direction the card is being swiped and modify your widget accordingly

### Trigger swipe up and swipe down through controller
You can now trigger swipe up and swipe down with our ```AppinioSwiperController``` regardless of the chosen ```AppinioSwipeDirection``` (which is still used when ```swipe``` is called through the controller). Just like the swipeLeft and swipeRight call, you can call ```swipeUp``` or ```swipeDown``` through the controller anywhere you want.

You can now trigger swipe up and swipe down with our ```AppinioSwiperController``` regardless of the chosen swipe
direction (which is still used when ```swipe``` is called through the controller). Just like the swipeLeft and
swipeRight call, you can call ```swipeUp``` or ```swipeDown``` through the controller anywhere you want.

### Restrict horizontal or vertical swipe

You can now restrict the swipe in either horizontal directions or vertical directions using ```swipeOptions``` property.

### Set looping for card swipe

Now you can set the ```loop``` property to ```true``` and make the list infinitely scrollable.

### Update the cards while swiping
In this version we have replaced the list of cards with ```cardsBuilder```. Now the widget only renders two cards at a time which makes it lightweight and scalable. So you can perform operations on your card anytime.

In this version we have replaced the list of cards with ```cardsBuilder```. Now the widget only renders two cards at a
time which makes it lightweight and scalable. So you can perform operations on your card anytime.

## Show Cases

Expand All @@ -75,22 +103,26 @@ Customize the threshold of the swiper, when the card should slide away...
## Installation

Create a new project with the command

```yaml
flutter create MyApp
```

Add

```yaml
appinio_swiper: ...
```
to your `pubspec.yaml` of your flutter project.
**OR**
run

```yaml
flutter pub add appinio_swiper
```
in your project's root directory.

in your project's root directory.

In your library add the following import:

Expand All @@ -101,7 +133,9 @@ import 'package:appinio_swiper/appinio_swiper.dart';
For help getting started with Flutter, view the online [documentation](https://flutter.io/).

## Usage
You can place your `AppinioSwiper` inside of a `Scaffold` or `CupertinoPageScaffold` like we did here. Optional parameters can be defined to enable different features. See the following example..

You can place your `AppinioSwiper` inside of a `Scaffold` or `CupertinoPageScaffold` like we did here. Optional
parameters can be defined to enable different features. See the following example..

```dart
import 'package:appinio_swiper/appinio_swiper.dart';
Expand All @@ -113,18 +147,21 @@ class Example extends StatelessWidget {
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
height: MediaQuery
.of(context)
.size
.height * 0.75,
child: AppinioSwiper(
cardsCount: 10,
onSwiping: (AppinioSwiperDirection direction){
onSwiping: (AppinioSwiperDirection direction) {
print(direction.toString());
},
cardsBuilder: (BuildContext context,int index){
return Container(
alignment: Alignment.center,
child: const Text(index.toString()),
color: CupertinoColors.activeBlue,
);
cardsBuilder: (BuildContext context, int index) {
return Container(
alignment: Alignment.center,
child: const Text(index.toString()),
color: CupertinoColors.activeBlue,
);
},
),
),
Expand All @@ -134,35 +171,42 @@ class Example extends StatelessWidget {
```

## Constructor
#### Basic

#### Basic

| Parameter | Default | Description | Required |
|------------------|:---------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------|:--------:|
| cardsCount | - | Number of cards you want to render | true |
| backgroundCardsCount | 1 | Number of cards you want to render in background | false |
| cardsBuilder | - | Callback of the type CardsBuilder | true |
| swipeOptions | - | value of type AppinioSwipeOptions to restrict swipes | false |
| controller | - | Trigger unswipe | false |
| cardCount | - | Number of cards you want to render. | true |
| backgroundCardCount | 1 | Number of cards you want to render in background. | false |
| backgroundCardScale | .9 | Scale factor for the background card. | false |
| backgroundCardOffset | - | Offset for the background card. | false |
| cardBuilder | - | Callback of the type CardsBuilder. | true |
| swipeOptions | - | value of type AppinioSwipeOptions to restrict swipes. | false |
| invertAngleOnBottomDrag | true | Sets whether the card should angle in the opposite direction when it is dragged from the bottom half. | false |
| controller | - | Trigger swipe, unSwipe and animateTo. | false |
| padding | EdgeInsets.symmetric(horizontal: 20, vertical: 25) | Control swiper padding | false |
| duration | 200 milliseconds | The duration that every animation should last | false |
| cardsSpacing | 40 | The spacing between background cards. | false |
| maxAngle | 30 | Maximum angle the card reaches while swiping | false |
| threshold | 50 | Threshold from which the card is swiped away | false |
| isDisabled | false | Set to ```true``` if swiping should be disabled, has no impact when triggered from the outside | false |
| onTapDisabled | - | Function that get triggered when the swiper is disabled | false |
| onSwipe | - | Called with the new index and detected swipe direction when the user swiped | false |
| onSwipeBegin | - | Called when user starts to swipe a card. | false |
| onSwipeEnd | - | Called swipe action completes. | false |
| onCardPositionChanged | - | Called when card position changes. | false |
| onEnd | - | Called when there is no Widget left to be swiped away | false |
| direction | right | Direction in which the card is swiped away when triggered from the outside | false |
| defaultDirection | right | Direction in which the card is swiped away when triggered from the outside | false |
| allowUnswipe | true | Set to ```false``` if unswipe should be disabled away | false |
| unlimitedUnswipe | false | Set to ```true``` if the user can unswipe as many cards as possible | false |
| unswipe | - | Called with the boolean ```true``` when the last card gets unswiped and with the boolean ```false``` if there is no card to unswipe | false |
| onSwiping | - | Pass a callback of type ```void Function(AppinioSwiperDirection direction)``` and check when and in which direction the card is getting swiped | false |
| onUnswipe | - | Called with the boolean ```true``` when the last card gets unswiped and with the boolean ```false``` if there is no card to unswipe | false |
| onSwipeCancelled | - | Gets called when the user leaves the card before the threshold is reached | false |

#### Controller

The ```Controller``` is used to control the ```swipe```, ```swipeLeft```, ```swipeRight```, ```swipeUp```, ```swipeDown``` or ```unswipe``` function of the swiper from outside of the widget. You can create a controller called ```AppinioSwiperController``` and save the instance for further usage. Please have a closer look to our Example for the usage.
The ```Controller``` is used to control the ```swipeDefault```, ```swipeLeft```, ```swipeRight```, ```swipeUp```
, ```swipeDown``` , ```unswipe``` and ```animateTo``` function of the swiper from outside of the widget. You can create a controller
called ```AppinioSwiperController``` and save the instance for further usage. Please have a closer look to our Example
for the usage.

| Method | Description |
|------------|:---------------------------------------------------------------------------------------------------|
Expand All @@ -172,6 +216,7 @@ The ```Controller``` is used to control the ```swipe```, ```swipeLeft```, ```swi
| swipeUp | Changes the state of the controller to swipe up and swipes the card to the up side. |
| swipeDown | Changes the state of the controller to swipe down and swipes the card to the down side. |
| unswipe | Changes the state of the controller to unswipe and brings back the last card that was swiped away. |
| animateTo | Animates the current offset of the card on top to the required Offset in a given duration. |

<hr/>
Made with ❤ by Flutter team at <a href="https://appinio.app">Appinio GmbH</a>
6 changes: 5 additions & 1 deletion packages/appinio_swiper/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include: package:flutter_lints/flutter.yaml
#include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

linter:
rules:
- unawaited_futures
2 changes: 1 addition & 1 deletion packages/appinio_swiper/example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
# include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
Expand Down
2 changes: 1 addition & 1 deletion packages/appinio_swiper/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion packages/appinio_swiper/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
3 changes: 2 additions & 1 deletion packages/appinio_swiper/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
# https://stackoverflow.com/questions/76230485/flutter-application-on-android-private-final-java-lang-string-java-io-file-path
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Loading

0 comments on commit bd9f10e

Please sign in to comment.