photo_view icon indicating copy to clipboard operation
photo_view copied to clipboard

[BUG]Wrapping PhotoViewGallery.builder inside GestureDetector, make GestureDetector onLongPress not working on iOS

Open anchao-lu opened this issue 4 years ago • 3 comments

Describe the bug 've wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }

anchao-lu avatar Oct 30 '20 09:10 anchao-lu

Describe the bug 've wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }

on iOS Simulator is ok

anchao-lu avatar Oct 30 '20 10:10 anchao-lu

Describe the bug Wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }

on iOS Simulator is ok

anchao-lu avatar Nov 03 '20 07:11 anchao-lu

I found the same problem

Hynsen avatar Nov 18 '20 06:11 Hynsen