Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ✨ Floating card animation #144

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

aditya-css
Copy link
Collaborator

  • Created flutter plugin structure.
  • Added method and event channel for passing gyroscope sensor data from native side (ios and android).
  • Added cursor_listener.dart for listening to cursor movement on desktop and website.
  • Added floating_event.dart to represent the movement data.
  • Added floating_controller.dart to house x and y axis points and have transformation logic to move the widget as per movement data.
  • Updated readme.md to reflect latest addition of floating animation feature.

@aditya-css aditya-css changed the title ✨ Floating card animation Feat: ✨ Floating card animation Sep 4, 2023
@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 5 times, most recently from 908ad8a to d9e58d1 Compare September 6, 2023 13:10
README.md Outdated
@@ -9,7 +9,9 @@ A Flutter package allows you to easily implement the Credit card's UI easily wit

## Preview

![The example app running in Android](https://github.com/simformsolutions/flutter_credit_card/blob/master/readme_assets/preview.gif)
<img src="readme_assets/preview.gif" alt="The example app showing credit card widget" width="240" height="451"/>
<img src="readme_assets/credit_card_float_preview.gif" alt="The example app showing card floating animation in mobile" width="207" height="448"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed update gif

README.md Outdated
@@ -109,6 +111,20 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
),
```

*Floating Card*

Make sure to call `CreditCardWidget.instance.initialize()` before using `CreditCardWidget` with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to handle this intialization internally. CreditCardWidget.instance.initialize()

@@ -0,0 +1,64 @@
group 'com.simform.flutter_credit_card'
version '3.0.7'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the package version? if yes can we make this dynamic?

import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.EventChannel.EventSink

private const val FPS_60 = 16666
Copy link
Collaborator

@vatsaltanna vatsaltanna Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this and use static value directly


override fun onListen(arguments: Any?, events: EventSink) {
sensorEventListener = createSensorEventListener(events)
sensorManager.registerListener(sensorEventListener, sensor, FPS_60)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use value directly here.

@@ -0,0 +1,6 @@
package com.simform.flutter_credit_card_example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this file necessary to add can we delete this file if not required?

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch from d9e58d1 to e64a327 Compare September 9, 2023 13:52
@kavantrivedi kavantrivedi force-pushed the feature/floating_animation_web_interface branch from e64a327 to 2146540 Compare September 10, 2023 07:09
import 'package:flutter_credit_card/credit_card_brand.dart';
import 'package:flutter_credit_card/flutter_credit_card.dart';

void main() => runApp(MySample());
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to add this code ?

labelText: 'Expired Date',
hintText: 'XX/XX',
CreditCardWidget(
shouldFloat: useFloatingAnimation,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of should use enable word. shouldFloat > enableFloatingCard

hintText: 'XX/XX',
CreditCardWidget(
shouldFloat: useFloatingAnimation,
shouldAddGlare: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this parameters are dependant on floating card so instead o separate parameter we can create a class like FloatingCardConfig

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use simform favicon here.

final double screenWidth = constraints.maxWidth.isInfinite
? MediaQuery.of(context).size.width
: constraints.maxWidth;
final double screenHeight = MediaQuery.of(context).size.height;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take variable for MediaQuery.of(context).size

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in next PR where inheritedModel is utilised (i.e. MediaQuery.sizeOf()) as Dart 3 support is enabled in it.

.withOpacity(AppConstants.minShadowOpacity),
offset: Offset(
floatingController!.y * 100,
-floatingController!.x * 100 + 8,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason to add 8 here? @kavantrivedi @aditya-chavda

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to have the shadow a below the card widget by 8 pixel. Want me to add comment there expressing the same?

_gradientSetup();
_updateRotations(false);
}

@override
void didChangeDependencies() {
orientation = MediaQuery.of(context).orientation;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write this code like this ?
orientation ??= MediaQuery.of(context).orientation;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be better to always use the updated values of the MediaQuery object.

? AppConstants.creditCardPadding
: widget.padding;

return CursorListener(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I belive this is only used as listner so can we avoid this widget from build and use some other workaround?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct, but it listens over a particular region, which would be the credit card widget, and thus it is in the build method.

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 2 times, most recently from edb21a4 to 2c12a36 Compare September 11, 2023 17:00

override fun onListen(arguments: Any?, events: EventSink) {
sensorEventListener = createSensorEventListener(events)
sensorManager.registerListener(sensorEventListener, sensor, 16666)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use constant instead of directly as a value. Also document that what this constant does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with @vatsaltanna 's request to revert using const variable for that value.


init(motionManager: CMMotionManager) {
self.motionManager = motionManager
self.motionManager!.gyroUpdateInterval = 0.016666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use constant instead of directly as a value. Also document that what this constant does.

Also have you taken into account higher refresh rate devices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vatsaltanna please advice on accounting device's refresh rate instead of fixed 60 fps.

lib/credit_card_background.dart Show resolved Hide resolved
color: shadowConfig!.color,
offset: shadowConfig!.offset +
Offset(
floatingController!.y * 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use contant.

lib/credit_card_background.dart Show resolved Hide resolved
lib/credit_card_background.dart Show resolved Hide resolved

bool isAnimating = false;

double get glarePosition =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some documentation above this getter so that anyone can understand what this logic does.

///initialize the animation controller
controller = AnimationController(
duration: widget.animationDuration,
vsync: this,
);

controller.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.forward) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition can be simplified like this

isAnimating =  status == AnimationStatus.forward || status == AnimationStatus.reverse;

lib/floating_animation/cursor_listener.dart Show resolved Hide resolved
@@ -109,6 +120,36 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
),
```

*Floating Card*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a row of check boxes with indicating supported platform should also be added

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that would be counter intuitive as we are currently not supporting only mobile web.

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 3 times, most recently from 5d19797 to ee2e2d5 Compare September 13, 2023 14:18
color: bgColor,
image: DecorationImage(
image: ExactAssetImage(
isLightTheme ? 'assets/bg-white.png' : 'assets/bg.png',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert assets/bg.png > assets/bg-dark.png and assets/bg-white.png > assets/bg-light.png

enabledBorder: border,
labelText: 'Card Holder',
CreditCardWidget(
floatConfig: !useFloatingAnimation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead o negation sign switch the condition and code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use a flag to enable floating animation. like enableFloatingCard and use floatConfig as configuration only if it is null then use default values

lib/credit_card_background.dart Show resolved Hide resolved
? null
: FloatConfig(
isGlareEnabled: true,
shadowConfig: FloatShadowConfig.preset(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider null as default value instead of FloatShadowConfig.preset()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will by default disable the shadow effect. Can you kindly confirm if that is okay?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the idea over here is to have a flag to enable or disable shadow which is by default enabled and the purpose of config will only be to change the paramteres of shadow.

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 3 times, most recently from fd3042a to 9b421db Compare September 18, 2023 11:02
@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch from 9b421db to 751e11d Compare September 18, 2023 11:37
import 'floating_animation/floating_event.dart';
import 'flutter_credit_card_platform_interface.dart';

const String _methodChannelName = 'com.simform.flutter_credit_card';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets added channel names and method name to constant file.

AppConstants.defaultGlareColor.withOpacity(0.1),
AppConstants.defaultGlareColor.withOpacity(0.07),
AppConstants.defaultGlareColor.withOpacity(0.05),
];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of static member can we create a getter for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating getter would cause creation of the object in question again and again on every usage of it. I believe using this way would save that case.

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 2 times, most recently from 4912cef to 1a42482 Compare September 19, 2023 12:39

dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove these dependencies

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch 2 times, most recently from ce48ed9 to 4d7bc9e Compare September 20, 2023 11:08
Copy link
Contributor

@ujas-m-simformsolutions ujas-m-simformsolutions left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

CHANGELOG.md Outdated
@@ -1,6 +1,8 @@
# [3.0.8](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/3.0.8) (Unreleased)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use major version here

@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch from 4d7bc9e to 5d1935a Compare September 22, 2023 09:35
pubspec.yaml Outdated
@@ -1,22 +1,36 @@
name: flutter_credit_card
description: A Credit Card widget package, support entering card details, card flip animation.
description: A Credit Card widget package with support of entering card details, and animations like card flip
and float.
version: 3.0.8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

- Added support for light and dark theme in example app.
- Added preview for floating card animation with theme change in README.md.
- Fixed github action workflow status url in README.md.
- Added missing parameters in CreditCardWidget and CardCardForm in README.md.
@aditya-css aditya-css force-pushed the feature/floating_animation_web_interface branch from 5d1935a to 38a3a70 Compare September 22, 2023 09:39
@vatsaltanna vatsaltanna merged commit 8df0fd6 into master Sep 22, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants