react-native-hole-view icon indicating copy to clipboard operation
react-native-hole-view copied to clipboard

Holes have black background on android devices since 0.75.1

Open bnemeth-parkl opened this issue 1 year ago • 10 comments
trafficstars

Error

On android devices the holes are black with zero opacity since react native 0.75.1 upgrade. It was working fine on 0.74.6.

Steps to reproduce

  1. Create new React native repo with version 0.75.X
  2. Add react-native-hole-view dependency (alpha4)
  3. Used RNHoleView in existing App.tsx
  4. Run on Android Device

sample repo: https://github.com/bnemeth-parkl/RNHoleViewBlackHoleDemo

bnemeth-parkl avatar Oct 04 '24 11:10 bnemeth-parkl

Same here

GolliAch avatar Oct 22 '24 21:10 GolliAch

same on react-native 0.75.3. can we waiting for fix the problem or this library is not longer supported?

realmizzer avatar Oct 30 '24 08:10 realmizzer

Same issue here!

denisbevilacqua avatar Nov 11 '24 18:11 denisbevilacqua

+1

TheAdamBorek avatar Nov 21 '24 11:11 TheAdamBorek

+1

dcorbin avatar Nov 24 '24 19:11 dcorbin

Anybody tried it on 0.75.0 version of react? Just to narrow down the source of the problem?

dcorbin avatar Nov 24 '24 20:11 dcorbin

Guys, we’re sorry, but we’re currently unable to address this issue as our main project is still on React <0.70.

If anyone is able to fix it and submit a PR, we’d greatly appreciate it!

stephenkopylov avatar Nov 25 '24 09:11 stephenkopylov

For others blocked by this problem: I was able to replace my usage of RHNV with SVG based masking:

import React from 'react';
import { View, StyleSheet } from 'react-native';
import Svg, { Rect, Circle, Mask, Defs } from 'react-native-svg';

const HoleView = () => {
  return (
    <View style={styles.container}>
      <Svg height="100%" width="100%">
        <Defs>
          <Mask id="mask" x="0" y="0" width="100%" height="100%">
            <Rect width="100%" height="100%" fill="white" />
            <Circle cx="100" cy="100" r="50" fill="black" />
          </Mask>
        </Defs>
        <Rect width="100%" height="100%" fill="rgba(0, 0, 0, 0.8)" mask="url(#mask)" />
      </Svg>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default HoleView;

It's not drop-in, and I have not been able to animate the movement of the hole. Also, I don't need touch access through the hole, just visual appearance.

dcorbin avatar Nov 27 '24 18:11 dcorbin

An ugly hack that worked for me.

Step 1. Remove RN background:

backgroundColor: Platform.OS === 'android' ? 'clear' : rgba(0, 0, 0, 0.85)

Step 2. Patch RNHoleView.kt (node_modules/react-native-hole-view/android/src/main/java/com/ibitcy/react_native_hole_view/RNHoleView.kt):

// 2.1 Remove the onDraw method

// 2.2 Duplicate the background color
private val customBackgroundColor = ColorUtils.setAlphaComponent(
    Color.parseColor("#000000"),
    (0.85 * 255).toInt()
)

// 2.3 Rework dispatchDraw
override fun dispatchDraw(canvas: Canvas) {
    if (mHolesPath != null) {
        val layerId = canvas.saveLayer(
            0F, 0F,
            canvas.width.toFloat(), canvas.height.toFloat(), null, Canvas.ALL_SAVE_FLAG
        )
        canvas.drawColor(customBackgroundColor)
        canvas.drawPath(mHolesPath!!, mHolesPaint)
        canvas.restoreToCount(layerId);
    }
    super.dispatchDraw(canvas)
}

I took the code from here. Not sure about performance.

--

Another idea. Still requires clear RN background style.

Instead of drawing the holes, let 's draw the background. Here is the paint object code:

mHolesPaint = Paint(Paint.ANTI_ALIAS_FLAG)
mHolesPaint.color = Color.argb(217, 0, 0, 0)
mHolesPaint.style = Paint.Style.FILL

Then the path creation starts with a background rect:

mHolesPath = Path()
mHolesPath!!.setFillType(Path.FillType.WINDING);
mHolesPath!!.addRect(0F, 0F, width.toFloat(), height.toFloat(), Path.Direction.CW);

And all addRoundRect calls require Path.Direction.CCW option.

isTouchInsideHole requires the inverted condition:

return !clickableRegion.contains(touchX, touchY)

vladvlasov256 avatar Dec 01 '24 09:12 vladvlasov256

same :(

Screenshot 2025-01-13 at 23 00 12

retyui avatar Jan 13 '25 22:01 retyui

Same issue is observved on React Native 0.79.2 as well.

vikrantnegi avatar Jul 18 '25 11:07 vikrantnegi

I'm reproducing it with "react-native": "0.79.5 and "@react-navigation/native": "7.1.17", only in a react navigation Modal. I don't reproduce the problem in a react-native <Modal />

zabojad avatar Sep 04 '25 14:09 zabojad

Try this solutions. Wrap the hole view component in a View like this:

<View renderToHardwareTextureAndroid={true}>
    <HoleView />
</View>

vikrantnegi avatar Sep 11 '25 09:09 vikrantnegi

@vikrantnegi it works ! How did you find this?

zabojad avatar Sep 15 '25 13:09 zabojad