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

Revert "Add a magnifying glass example (#2419)" #2483

Merged
merged 1 commit into from
Jun 14, 2024
Merged

Conversation

wcandillon
Copy link
Contributor

This reverts commit 391fb9a.

@wcandillon
Copy link
Contributor Author

@rayronvictor my apologies for the revert. I found some issues with the example. Some I could fix, some that would take a bit more time to fix.

One easy one is that it should use gesture handler instead of onTouch:

  const gesture = Gesture.Pan()
    .onStart((e) => {
      touchPosX.value = e.x;
      touchPosY.value = e.y;
      drawing.value = 1;
    })
    .onChange((e) => {
      touchPosX.value = e.x;
      touchPosY.value = e.y;
    })
    .onEnd(() => {
      drawing.value = 0;
    });

The other one that would take more time to address (but if you would like to, I would love to merge it), is that this example should probably not use RuntimeShader but rather Shader (and have ImageShader as a child) and in the uniform you should know the dimensions of the image so that you can sample it properly and benefit from a "real zoom" effect if that makes sense.

Let me know your thoughts on this and my apologies for the mix up.

@wcandillon wcandillon merged commit 6a8e64e into main Jun 14, 2024
9 checks passed
Copy link
Contributor

🎉 This PR is included in version 1.3.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@rayronvictor
Copy link
Contributor

Hi @wcandillon,

No worries at all, and thank you for pointing out the issues!

I switched to the gesture handler as you suggested and changed to Shader/ImageShader. Should I open another Pull Request?

@rayronvictor
Copy link
Contributor

Gravacao.de.Tela.2024-06-14.as.17.06.43.mp4
const gesture = Gesture.Pan()
  .minDistance(0)
  .onBegin((e) => {
    touchPosX.value = e.x;
    touchPosY.value = e.y;
    drawing.value = 1;
  })
  .onChange((e) => {
    touchPosX.value = e.x;
    touchPosY.value = e.y;
  })
  .onFinalize(() => {
    drawing.value = 0;
  });
    
const uniforms = useDerivedValue(() => {
  return {
    screen: vec(canvasWidth.value, canvasHeight.value),
    touchPos: vec(touchPosX.value, touchPosY.value),
    drawing: drawing.value,
    zoomLevel: zoomLevel.value,
    magnifierDiameter: magnifierDiameter.value,
    isFixed: isFixedSharedValue.value,
  };
});

<GestureDetector gesture={gesture}>
  <Canvas
    style={StyleSheet.absoluteFill}
    mode="continuous"
    onLayout={handleCanvasLayoutChange}
  >
    <Fill>
      <Shader source={source} uniforms={uniforms}>
        <ImageShader
          image={image}
          fit="cover"
          x={0}
          y={0}
          width={canvasWidth}
          height={canvasHeight}
        />
      </Shader>
    </Fill>
  </Canvas>
</GestureDetector>

@rayronvictor
Copy link
Contributor

PR created #2485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants