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

[BUG] undefined is not an object (evaluating '_react2.PropTypes.number') #2

Open
mnlbox opened this issue Mar 10, 2018 · 5 comments
Open

Comments

@mnlbox
Copy link

mnlbox commented Mar 10, 2018

Hi,
I install this package and import this but it's return below error:

undefined is not an object (evaluating '_react2.PropTypes.number')
<unknown>
CornerLabel.js:44:32
...

/CC: @cyqresig

@mnlbox mnlbox changed the title undefined is not an object (evaluating '_react2.PropTypes.number') [BUG] undefined is not an object (evaluating '_react2.PropTypes.number') Mar 10, 2018
@nmvuong92
Copy link

open CornerLabel.js

  1. remove PropTypes from
    import React, {
    PropTypes,
    Component,
    } from 'react';

  2. remove:
    static propTypes = {
    style: View.propTypes.style,
    textStyle: Text.propTypes.style,
    cornerRadius: PropTypes.number.isRequired,
    alignment: PropTypes.oneOf([
    'left',
    'right',
    ])
    }

@mnlbox
Copy link
Author

mnlbox commented Mar 16, 2018

Thanks @nmvuong92
So I think we need some update and PR on this package.
@cyqresig Have you still working on this package?

@steevn
Copy link

steevn commented Mar 16, 2018

I've created a pull request for this issue.

@liweijieok
Copy link

you can copy the CornerLabel.js in you react project.
then add prop-types into you package.json.
modify the copty file as bellow


import PropTypes from "prop-types";
import React, {
    Component,
} from "react";
import {
    StyleSheet,
    View,
    Text,
} from "react-native";

const styles = StyleSheet.create({
    container: {
        position: "absolute",
        //transform: [{rotate: '45deg'}],
        justifyContent: "flex-end",
    },
    label: {
        justifyContent: "center",
        alignItems: "center",
    },
    text: {
        color: "#fff",
        // fontFamily: '.HelveticaNeueInterface-MediumP4',
        fontSize: 12,
    },
});

export default class CornerLabel extends Component {

    static defaultProps = {
        alignment: "left",
    };

    static propTypes = {
        style: View.propTypes.style,
        textStyle: Text.propTypes.style,
        cornerRadius: PropTypes.number.isRequired,
        alignment: PropTypes.oneOf([
            "left",
            "right",
        ])
    };

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};

        this._labelHeight = Math.sqrt(Math.pow(props.cornerRadius, 2) / 2);
        this._labelWidth = this._labelHeight * 2;
        let originOffset = Math.sqrt(Math.pow(this._labelHeight / 2, 2) / 2);
        let labelHorizontalPosition = -this._labelWidth / 2 + originOffset;
        let labelVerticalPosition = -this._labelHeight / 2 + originOffset;
        if (props.alignment === "left") {
            this._labelPosition = {left: labelHorizontalPosition, top: labelVerticalPosition};
            this._labelTransform = {transform: [{rotate: "-45deg"}]};
        }
        else {
            this._labelPosition = {right: labelHorizontalPosition, top: labelVerticalPosition};
            this._labelTransform = {transform: [{rotate: "45deg"}]};
        }

    }

    render() {
        return (
            <View style={[styles.container,
                this._labelPosition,
                this._labelTransform,
                {width: this._labelWidth, height: this._labelHeight,},
            ]}>
                <View style={[styles.label,
                    {height: this._labelHeight},
                    this.props.style,
                ]}>
                    {this._renderChildren()}
                </View>
            </View>
        );
    }

    _renderChildren() {
        return React.Children.map(this.props.children, (child) => {
            if (!React.isValidElement(child)) {
                return <Text style={[styles.text, this.props.textStyle]}>{child}</Text>;
            }
            return child;
        });
    }

}

it't work for me.

@geminiyellow
Copy link

geminiyellow commented Mar 7, 2019

is it still alive ? @cyqresig

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

5 participants