Skip to content

Commit

Permalink
Detect if Text.propTypes actually exists for web (#11)
Browse files Browse the repository at this point in the history
I'm using [react-native-web](https://github.com/necolas/react-native-web) in conjunction with this library in order to support more platforms with the same codebase.

When building our app for development, everything works properly and this library does exactly what we need it to.

However, react-native-web excludes propTypes when you do a production build in order to reduce bundle size and improve performance.

This leads to [issues](necolas/react-native-web#423) when libraries depend on propTypes being defined.

I propose feature-detecting whether Text.propTypes is actually defined so that people using react-native-web, or any bundlers for native that reduce size agressively, without affecting current users.
  • Loading branch information
RangerMauve authored and obipawan committed Apr 14, 2017
1 parent 85a0c79 commit 378a943
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Hyperlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import React, { Component, PropTypes } from 'react'
import { View, Text } from 'react-native'

const textPropTypes = Text.propTypes || {};

class Hyperlink extends Component {
constructor(props){
super(props)
Expand Down Expand Up @@ -95,13 +97,13 @@ class Hyperlink extends Component {

Hyperlink.propTypes = {
linkify: PropTypes.object,
linkStyle: Text.propTypes.style,
linkStyle: textPropTypes.style,
linkText: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]),
onPress: React.PropTypes.func,
onLongPress: React.PropTypes.func,
onPress: PropTypes.func,
onLongPress: PropTypes.func,
}

module.exports = Hyperlink

1 comment on commit 378a943

@necolas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this should be unnecessary once this bug is fixed - oliviertassinari/babel-plugin-transform-react-remove-prop-types#95

Please sign in to comment.