photo_view icon indicating copy to clipboard operation
photo_view copied to clipboard

customChild is unable to receive touch event

Open cbenhagen opened this issue 6 years ago • 13 comments

In the following simple example I am unable to press the left or right button:

import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final List<String> buttonNames = ['left', 'middle', 'right'];

  @override
  Widget build(BuildContext context) {
    return PhotoView.customChild(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: buttonNames
            .map((n) => Container(
                  width: 100,
                  child: RaisedButton(
                      child: Text(n),
                      onPressed: () {
                        print('pressed $n');
                      }),
                ))
            .toList(),
      ),
      childSize: Size(1000, 200),
    );
  }
}

cbenhagen avatar Jan 12 '19 17:01 cbenhagen

The whole child of PhotoView.customChild will be wrapped in a GestureDetector. This bug is related to GestureArenaManager prioritizing the gestures in the built inGestureDetector. We should use RawGestureDetector.

renancaraujo avatar Jan 12 '19 19:01 renancaraujo

So why doesn't this happen with the middle button? Seemed more like a transform issue to me.

cbenhagen avatar Jan 13 '19 02:01 cbenhagen

Any update on this?

jvictorsoto avatar Apr 04 '19 22:04 jvictorsoto

@jvictorsoto Unfortunately I have been unable to apply so much time working on PhotoView in the last month. So... nope, not much progress on this. But every bug tagged issue is a priority right now, including this very one.

renancaraujo avatar Apr 08 '19 12:04 renancaraujo

After some investigation, I've reached into https://github.com/flutter/flutter/issues/27587 and https://github.com/flutter/flutter/issues/25702

Hence it seems like a Flutter issue.

renancaraujo avatar May 08 '19 02:05 renancaraujo

It seems like will be solved at https://github.com/flutter/flutter/pull/32192

renancaraujo avatar May 08 '19 02:05 renancaraujo

Any idea if this issue on flutter has been solved? I'm using Channel beta, v1.6.3, and still can't tap on widgets inside the custom child

mendieta avatar Jun 29 '19 23:06 mendieta

It seems like it wasn't related to that bugfix. This was merged into flutter master on Jun 1. But even now on the master channel the same issue keeps happening. Tested it with flutter v1.10.15-pre.23.

thomasostfeld avatar Oct 09 '19 05:10 thomasostfeld

No, it was not. But flutter/flutter#27587 and flutter/flutter#25702 are still open. I will try some workaround, but since this is a framework bug, I don't think we can do much here.

renancaraujo avatar Oct 16 '19 08:10 renancaraujo

I don't really think this is a framework bug. For example

SingleChildScrollView(
  scrollDirection: Axis.horizontal,
  controller: horizontalScrollController,
  child: SingleChildScrollView(
    scrollDirection: Axis.vertical,
    controller: verticalScrollController,
    child: child, // must be big enough to be scrollable
  ),
)

This also hides Buttons which are not visible but you can scroll to them and click them. I guess one would need to adapt whatever is done in the SingleChildScrollViews and adapt it to this library.

ueman avatar Feb 05 '20 12:02 ueman

This also hides Buttons which are not visible but you can scroll to them and click them. I guess one would need to adapt whatever is done in the SingleChildScrollViews and adapt it to this library.

That is because scroll views work on a totally different way for a very different purpose. Scrolls uses the sliver protocol, that are basically made for that: scrolls in one axis.

Photo view uses simple matrix transformations, that happens after layout.

renancaraujo avatar Jul 05 '21 10:07 renancaraujo

Since there is no intention for the framework team to fix transformed gesture detectors, here is a tip for anyone facing this problem: try to wrap photo view with a gesture detector externally.

renancaraujo avatar Jul 05 '21 10:07 renancaraujo

Since there is no intention for the framework team to fix transformed gesture detectors, here is a tip for anyone facing this problem: try to wrap photo view with a gesture detector externally.

what do you mean externally? can you give example?

taskindrp avatar Apr 24 '24 13:04 taskindrp