Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
920 stars 208 forks source link

Zoom in/out not working properly #261

Closed ToyZ-95 closed 1 year ago

ToyZ-95 commented 1 year ago

Steps to Reproduce

Just try to zoom by pinching it

Expected results

It should zoom gradually

Actual results

It zooms to max or too much on one pinch

About your device

Any device

Your flutter version

Flutter 3.7.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7048ed95a5 (4 weeks ago) • 2023-02-01 09:07:31 -0800 Engine • revision 800594f1f4 Tools • Dart 2.19.1 • DevTools 2.20.1

GabrielAraujo commented 1 year ago

I was having this problem too so I ended controlling on my end using GestureDetector and opaque hit behavior.

GabrielAraujo commented 1 year ago

One thing that happens on some devices is the zoom is too maxed out when you change from 0.0 to 0.2 for example.

ToyZ-95 commented 1 year ago

I was having this problem too so I ended controlling on my end using GestureDetector and opaque hit behavior.

May I request you to provide me a little demo or something that I can use it?

GabrielAraujo commented 1 year ago
final _zoomScaleFactor = .1;
final _previousZoomValue = ValueNotifier(0.0);

return state.when(
                  onPreparingCamera: (state) => const Center(
                    child: CircularProgressIndicator(),
                  ),
                  onPhotoMode: (state) => GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onScaleUpdate: (details) async {
                      final scale = details.scale;

                      final result =
                          _previousZoomValue.value * scale - _zoomScaleFactor;

                      if (result > 0 && result < 1) {
                        await state.sensorConfig.setZoom(result);
                      }
                    },
                    onScaleStart: (_) {
                      _previousZoomValue.value = zoom + _zoomScaleFactor;
                    },
                    child: Container(),
                  ),
                );
ToyZ-95 commented 1 year ago

state.when( onPreparingCamera: (state) => const Center( child: CircularProgressIndicator(), ), onPhotoMode: (state) => GestureDetector( behavior: HitTestBehavior.opaque, onScaleUpdate: (details) async { final scale = details.scale;

                  final result =
                      _previousZoomValue.value * scale - _zoomScaleFactor;

                  if (result > 0 && result < 1) {
                    await state.sensorConfig.setZoom(result);
                  }
                },
                onS

Thank you very much for the help, I will definitely implement it and update it here

g-apparence commented 1 year ago

@GabrielAraujo Thank you sharing this 👏 This could help us if you could make a PR about your changes.

ToyZ-95 commented 1 year ago

Hi @g-apparence I have created PR which fixes zoom in/out problem. Credit goes to @GabrielAraujo as he provided the basic solution, I just modified it and make it work properly.

Here is the link to PR: https://github.com/Apparence-io/CamerAwesome/pull/263

g-apparence commented 1 year ago

Ok, @apalala-dev had some questions about this. I'll try to investigate a bit too to understand this. (Didn't had much times these days sorry).

J-apparence commented 1 year ago

I made a PR #270. Could you test it and tell me if it's okay ?