question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android render not correctly

See original GitHub issue

Bug

I’m trying to create view like this https://i.imgur.com/q2NMUOQ.jpg . Please check the comment section. It has gradient opacity at top. So, I’m doing it like this :

<View style={{ backgroundColor: '#abcdef' }}
<MaskedView
      maskElement={(
        <LinearGradient colors={['rgba(0,0,0,0)', 'rgba(0,0,0,1)']} style={{
              flex: 1,
            }} start={{ x: 0, y: 0 }} end={{ x: 0, y: 1 }} locations={[0,0.5]} />
      )}
>
    <View style={{ width: 100, height: 40, elevation: 5, backgroundColor: 'red'  }} />
    <View style={{ width: 100, height: 40, elevation: 5, backgroundColor: 'red'  }} />
..........
    <View style={{ width: 100, height: 40, elevation: 5, backgroundColor: 'red'  }} />
</MaskedView>
</View>

It works fine on ios but wrong on android. Please check screenshot https://i.imgur.com/zZpPSzs.png

On android, it black at bottom. How to remove it ? Thank you

Environment info

React native info output:

 info
  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 46.73 MB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.16.0 - /usr/local/bin/node
      Yarn: 1.17.3 - /usr/local/bin/yarn
      npm: 6.10.2 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 24, 26, 27, 28, 29
        Build Tools: 27.0.3, 28.0.3, 29.0.1
        System Images: android-27 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5692245
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.9 => 0.59.9
    npmGlobalPackages:
      react-native-cli: 2.0.1

Library version: “@react-native-community/masked-view”: “^0.1.1”

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

4reactions
kennymcommented, Aug 23, 2019

We’ve found a workaround for android, by setting the opacity of the element via a timeout of 50ms.

this.state.gradientColor = '#ffffff'

            <MaskedView
              style={{
                height: 50,
                width: '100%'
              }}
              maskElement={<LinearGradient colors={[this.state.gradientColor, 'transparent']} style={{ flex: 0.9 }} />}
            >

and a setTimeout which does the following:

      setTimeout(() => {
        this.setState({ gradientColor: "#ffffff01"})
      }, 50)

amazingly enough this works, but I’d be grateful if this weren’t needed.

1reaction
5up-okamuracommented, Jun 14, 2020

It works fine. key is the key to refreshing.

const GradientElement = () => {
    const [key, setKey] = useState(0)

    useEffect(() => {
        if (Platform.OS === 'android') {
            setTimeout(() => setKey((prev) => prev + 1), 0)
        }
    }, [])

    return (
        <MaskedView
            key={`${key}`}
            maskElement={<InnnerElement />}
        >
            <LinearGradient
                colors={['red','blue']}
                style={{ flex: 1 }}
            />
        </MaskedView>
    )
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio XML Widgets not rendering properly in designer
In android studio top right corner above layout display there is Toggle issue panel click on that and u will see one box...
Read more >
Slow rendering - Android Developers
If your app suffers from slow UI rendering, then the system is forced to skip frames and the user will perceive stuttering in...
Read more >
Android render not correctly · Issue #17 · react-native-masked ...
We've found a workaround for android, by setting the opacity of the element via a timeout of 50ms. this.state.gradientColor = '#ffffff' < ...
Read more >
Android Studio Rendering Problems | Tek Eye
This article discusses solutions to the Rendering Problems message sometimes seen in Android Studio. Sometimes, usually after a Studio ...
Read more >
RecyclerView does not render correctly. [36997736]
Android Studio 1.0 with SDK Tools 24, platform tools 21, build tools 21.1.1, and support library 21.0.2 still can't render recyclerview on Windows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found