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

maskElement not show #154

Open
fukemy opened this issue May 27, 2022 · 3 comments
Open

maskElement not show #154

fukemy opened this issue May 27, 2022 · 3 comments

Comments

@fukemy
Copy link

fukemy commented May 27, 2022

Hi, please help my problem, the maskview and text not show in simulator:

import React from "react";
import {
    View,
    Image,
    Dimensions,
    TouchableHighlight,
    TouchableOpacity,
    Text
} from "react-native";
import FastImage from "react-native-fast-image";
import { ThemeContext } from "../../context/ThemeContext";
import gradientParser from 'gradient-parser'
import LinearGradient from "react-native-linear-gradient";
import MaskedView from '@react-native-masked-view/masked-view';

export const RecentlyUserHeader = (props) => {
    const {theme} = React.useContext(ThemeContext)
    
    const generateUserName = (props) => {
        console.log('generateUserName', props.user.name)
        try {
            const gradient = gradientParser.parse(props.user.typeInfo.color)
            console.log('regex', gradient)
            const colors = gradient[0].colorStops.map((c) => {
                const t = c.value
                return `rgba(${t[0]}, ${t[1]}, ${t[2]}, ${[3]})`
            })
            const locations = gradient[0].colorStops.map((c) => {
                const l = c.length.value
                return l/100
            })
            // console.log('color', colors)
            return (
                <MaskedView
                    style={{ flex: 1 }}
                    maskElement={
                        <Text
                            numberOfLines={1}
                            ellipsizeMode='tail'
                            style={{
                                backgroundColor: 'red',
                                maxWidth: 120,
                                fontSize: 12,
                                fontWeight: '600',
                                color: 'black'
                        }}>cacasc</Text>
                    }>
                    <LinearGradient colors={colors} locations={locations} />
                    <View style={{backgroundColor: 'green'}}/>
                </MaskedView>
            )
        } catch(error) {
            console.log('make gradient failed', error)
            return (
                <Text
                    numberOfLines={1}
                    ellipsizeMode='tail'
                    style={{
                        maxWidth: 120,
                        fontSize: 12,
                        fontWeight: '600',
                        color: theme.defaultText
                    }}>{props.user.name}</Text>
            )
        }
    }

    return(
      <TouchableOpacity style={{
      }} onPress={() => {
        RootNavigation.push("Setting")
      }}>
        <View style={{
          flexDirection: 'column',
          justifyContent: 'center',
          backgroundColor: 'red',
          alignItems: 'center'
        }}>
          <FastImage source={{ uri: props.avt }}
            resizeMode='cover'
            size={26}
            style={{ 
              width: 26,
              height: 26,
              borderRadius: 13,
              backgroundColor: 'lightgray'
             }} />
          
             {generateUserName(props)}
        </View>
      </TouchableOpacity>
    )
  }

Log result:

generateUserName demo4
 LOG  regex [{"colorStops": [[Object], [Object], [Object]], "orientation": {"type": "angular", "value": "180"}, "type": "linear-gradient"}]

Screen Shot 2022-05-27 at 12 46 54
Here is the image that maskview not show

And here is the image when only display Text:
Screen Shot 2022-05-27 at 12 47 55

@luisfuertes
Copy link

have you been able to solve it?

@fukemy
Copy link
Author

fukemy commented Dec 13, 2022

Yes, need width property

@GezzaoLennar
Copy link

I'm still getting this problem, adding width to MaskedView didn't help
"@react-native-masked-view/masked-view": "^0.3.1", "react-native": "0.72.6",
Can someone help?

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

No branches or pull requests

3 participants