garblovians / react-native-svg-pan-zoom

Pan-zoom via two-finger "Google Maps"-style pinch and drag gestures
MIT License
26 stars 23 forks source link

Issue with the drag feature #3

Closed felixmagnell closed 6 years ago

felixmagnell commented 6 years ago

Hello, my issue is that the dragable object has no constrain. I can drag the component over the whole screen even if it's not wrapped under the same View. I don't want the svg object to go over the gray area, as seen in picture:

simulator screen shot - ipad air - 2018-06-15 at 17 31 26

This is my code:

return (

            <View style={{ flex: 1,
                backgroundColor: 'white',
                flexDirection: 'column',
                justifyContent: 'flex-start',
              }} onLayout={this.onLayout}
              >
              <View style={{ height: 100, width: null, backgroundColor: '#dcdcdc', flexDirection: 'row', 
              justifyContent: 'space-between' }}>
                <View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}>

              </View>
              </View>
              <SvgPanZoom
          canvasHeight  = {500}
          canvasWidth   = {500}
          minScale      = {0.5}
          initialZoom   = {0.7}
          onZoom        = {(zoom) => { console.log('onZoom:' + zoom) }}
          canvasStyle   = {{ backgroundColor: 'yellow' }}
          viewStyle     = {{ backgroundColor: 'green'  }}
        >

          {/* Doesn't consume or respond to clicks */}
          <Circle
            cx          = {100}
            cy          = {100}
            r           = {42}
            stroke      = "red"
            strokeWidth = "2.5"
            fill        = "blue"
          />

          {/* Responds to clicks */}
          <SvgPanZoomElement
            x ={50}
            y ={50}
            onClick         = {()=>{ console.log('onClick!') }}
            onClickCanceled = {()=>{ console.log('onClickCanceled!') }}
            onClickRelease  = {()=>{ console.log('onClickRelease!') }}
            onDrag          = {()=>{ console.log('onDrag!') }}
          >
            <Circle
              cx          = {42}
              cy          = {42}
              r           = {42}
              stroke      = "blue"
              strokeWidth = "2.5"
              fill        = "red"
            />
          </SvgPanZoomElement>

        </SvgPanZoom>

            </View>

          );
        }

Any ideas why it behaves like this?

Stalder commented 6 years ago

Did you try to set style overflow: 'hidden' for parent View?

felixmagnell commented 6 years ago

@Stalder Perfect! It worked! Thank you.