diff --git a/Example/App.js b/Example/App.js index d8cb6c9..bab8168 100644 --- a/Example/App.js +++ b/Example/App.js @@ -27,17 +27,24 @@ export default class App extends Component { this.state = { visible: false, - dismiss: false, reference: undefined } } _onPress (ref) { - this.setState({ visible: true, dismiss: false, reference: ref }); + this.setState({ visible: true, reference: ref }); // setTimeout(() => { - // this.setState({ dismiss: true }) + // this.setState({ visible: false }) // }, 1000) + + // Tooltips.Show(ref, { + // text: "Long Press Description" + // }) + + // setTimeout(() => { + // Tooltips.Dismiss(ref) + // }, 1000); } render() { @@ -51,9 +58,9 @@ export default class App extends Component { { this._onPress(ref); }} /> - { + { console.log("On Hide"); - }} /> + }} clickToHide={false} /> ; } } diff --git a/RNTooltips.js b/RNTooltips.js index 9fbcbb7..c79cee3 100644 --- a/RNTooltips.js +++ b/RNTooltips.js @@ -38,7 +38,6 @@ class Tooltips extends PureComponent { autoHide: PropTypes.bool, duration: PropTypes.number, clickToHide: PropTypes.bool, - dismiss: PropTypes.bool, corner: PropTypes.number, tintColor: PropTypes.string, textColor: PropTypes.string, @@ -56,7 +55,6 @@ class Tooltips extends PureComponent { position: 4, align: 2, autoHide: true, - dismiss: false, duration: Platform.OS === "android" ? 4000 : 4, clickToHide: false, corner: Platform.OS === "android" ? 30 : 0, @@ -69,31 +67,47 @@ class Tooltips extends PureComponent { }; static Show(ref, props) { + if (typeof ref !== 'number') { + ref = findNodeHandle(ref); + } + if (props.text === undefined) { props.text = Tooltips.defaultProps.text; - } else if (props.position === undefined) { + } + if (props.position === undefined) { props.position = Tooltips.defaultProps.position; - } else if (props.align === undefined) { + } + if (props.align === undefined) { props.align = Tooltips.defaultProps.align; - } else if (props.autoHide === undefined) { + } + if (props.autoHide === undefined) { props.autoHide = Tooltips.defaultProps.autoHide; - } else if (props.duration === undefined) { + } + if (props.duration === undefined) { props.duration = Tooltips.defaultProps.duration; - } else if (props.clickToHide === undefined) { + } + if (props.clickToHide === undefined) { props.clickToHide = Tooltips.defaultProps.clickToHide; - } else if (props.corner === undefined) { + } + if (props.corner === undefined) { props.corner = Tooltips.defaultProps.corner; - } else if (props.tintColor === undefined) { + } + if (props.tintColor === undefined) { props.tintColor = Tooltips.defaultProps.tintColor; - } else if (props.textColor === undefined) { + } + if (props.textColor === undefined) { props.textColor = Tooltips.defaultProps.textColor; - } else if (props.textSize === undefined) { + } + if (props.textSize === undefined) { props.textSize = Tooltips.defaultProps.textSize; - } else if (props.gravity === undefined) { + } + if (props.gravity === undefined) { props.gravity = Tooltips.defaultProps.gravity; - } else if (props.shadow === undefined) { + } + if (props.shadow === undefined) { props.shadow = Tooltips.defaultProps.shadow; - } else if (props.arrow === undefined) { + } + if (props.arrow === undefined) { props.arrow = Tooltips.defaultProps.arrow } @@ -107,31 +121,33 @@ class Tooltips extends PureComponent { } static Dismiss(ref) { + if (typeof ref !== "number") { + ref = findNodeHandle(ref); + } + RNTooltips.Dismiss(ref); } componentDidUpdate() { - if (this.props.visible && this.props.reference) { - if (this.props.dismiss) { - Tooltips.Dismiss(findNodeHandle(this.props.reference)) - } else { - Tooltips.Show(findNodeHandle(this.props.reference), { - text: this.props.text, - position: this.props.position, - align: this.props.align, - autoHide: this.props.autoHide, - duration: this.props.duration, - clickToHide: this.props.clickToHide, - corner: this.props.corner, - tintColor: this.props.tintColor, - textColor: this.props.textColor, - textSize: this.props.textSize, - arrow: this.props.arrow, - gravity: this.props.gravity, - shadow: this.props.shadow, - onHide: this.props.onHide - }); - } + if (this.props.visible === true && this.props.reference) { + Tooltips.Show(findNodeHandle(this.props.reference), { + text: this.props.text, + position: this.props.position, + align: this.props.align, + autoHide: this.props.autoHide, + duration: this.props.duration, + clickToHide: this.props.clickToHide, + corner: this.props.corner, + tintColor: this.props.tintColor, + textColor: this.props.textColor, + textSize: this.props.textSize, + arrow: this.props.arrow, + gravity: this.props.gravity, + shadow: this.props.shadow, + onHide: this.props.onHide + }); + } else if (this.props.visible === false && this.props.reference) { + Tooltips.Dismiss(findNodeHandle(this.props.reference)) } } diff --git a/ios/RNTooltips.xcodeproj/project.pbxproj b/ios/RNTooltips.xcodeproj/project.pbxproj index e8b5a74..f06ee94 100644 --- a/ios/RNTooltips.xcodeproj/project.pbxproj +++ b/ios/RNTooltips.xcodeproj/project.pbxproj @@ -131,7 +131,6 @@ 58B511D71A9E6C8500147676 /* Sources */, 58B511D81A9E6C8500147676 /* Frameworks */, 58B511D91A9E6C8500147676 /* CopyFiles */, - FA0E49E01FC8EB10CDF2A91A /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -222,21 +221,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - FA0E49E01FC8EB10CDF2A91A /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RNTooltips/Pods-RNTooltips-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/package.json b/package.json index 8020f55..5ede9c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-tooltips", - "version": "0.0.7", + "version": "0.0.8", "description": "React Native: Native Tooltip View", "main": "RNTooltips.js", "scripts": {