Giter Site home page Giter Site logo

react-native-tooltip's Introduction

react-native-tooltip

A react-native component from displaying tooltip. Uses UIMenuController.

Add it to your project

  1. Run npm install react-native-tooltip --save
  2. Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name" (Screenshot) then (Screenshot).
  3. Add libRNToolTipMenu.a to Build Phases -> Link Binary With Libraries (Screenshot).
  4. Whenever you want to use it within React code: var ToolTip = require('react-native-tooltip');

Usage

Props

  • actions: Array of actions [{text: 'Copy', onPress: () => Clipboard.set(this.someValue) }]
  • longPress: Boolean indicating if the tooltip should be showing on longPress, false by default.
  • arrowDirection: String indicating the direction of the tooltip arrow. Possible values are: up, down, left, right, and default. Default is default, which means to point up or down at the object of focus based on its location on the screen.

Props from TouchableHighlight.propTypes

  • activeOpacity
  • onHideUnderlay
  • onShowUnderlay
  • style
  • underlayColor

You can see the list on the react native website

Example

import React from 'react';
import {
  AppRegistry,
  StyleSheet,
  PixelRatio,
  View,
  Text,
} from 'react-native';

import ToolTip from 'react-native-tooltip';

export default class MyToolTip extends React.Component {
    state = {
        input: 'chirag'
    };
    
    handleCopyPress = () => {
        AlertIOS.alert(`Copy has been pressed!`);
    };
    
    handleOtherPress = () => {
        AlertIOS.alert(`Other has been pressed!`);
    };
    
    handleHide = () => {
        console.log('Tooltip did hide');
    };
    
    handleShow = () => {
        console.log('tooltip did show');
    };
    
    render() {
        return (
          <View style={{flex: 1, justifyContent: 'center'}}>
            <ToolTip
              ref='tooltip'
              actions={[
                {text: 'Copy', onPress: this.handleCopyPress },
                {text: 'Other', onPress: this.handleOtherPress }
              ]}
              onHide={this.handleHide}
              onShow={this.handleShow}
              underlayColor={'blue'}
              style={styles.selectedName}
            >
              <Text style={styles.welcome}>
                Press Here.
              </Text>
            </ToolTip>
          </View>
        );
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  textinputContainer: {
    marginTop: 20,
    justifyContent: 'center',
    alignItems: 'center',
  },
  textinput: {
    width: 60,
    marginVertical: 2,
    marginHorizontal: 2,
    borderWidth: 1 / PixelRatio.get(),
    borderRadius: 5,
    borderColor: '#c7c7cc',
    padding: 2,
    fontSize: 14,
    backgroundColor: 'white',
  },
});

AppRegistry.registerComponent('tooltip', () => tooltip);

Note

It is also possible to open the menu programmatically, by calling this.refs.theToolTip.showMenu(); ( theToolTip being the reference of the component). To hide menu this.refs.theToolTip.hideMenu(); (Though tooltip hides by itself, while using with drawer on specific gesture tooltip does not hide by default.)

Here is how it looks:

Demo gif

Special thanks

Special thanks to jrichardlai for refactoring the api and make it awesome.

react-native-tooltip's People

Contributors

chirag04 avatar doronpr avatar eliperkins avatar enahum avatar imartingraham avatar jedt avatar johakr avatar jrichardlai avatar sevachb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-tooltip's Issues

onLayout prop is missing x,y in callback's e.nativeEvent.layout

I'm dropping in Tooltip as a replacement for my existing components, iterated as rows inside a listview over a data array. For example, a row:

<ToolTip onLayout={(e) => console.log(index, `Summary ${rowID} onLayout:`, e.nativeEvent.layout)}>
  <Text ...>
</ToolTip>

console logs would return for each row, e.nativeEvent.layout.width and .height as expected. .x and .y however always return 0, while TouchableHighlight returns the x,y coordinates of the rendered component as documented (React Native).

Is this a bug that e.nativeEvent.layout is not fully inherited from TouchableHighlight, or rather, the parent touchablewithoutfeedback?

Tooltip style change.

Hey,

I am trying to change tooltip styling but seems like there is no option to change. Is there any way to modify styling of tooltip ?

Thanks,

Please specify compatible version for Reac-native version

in my react-native version 0.39 this library not works.

I had to do magic to find the correct version and with a lot of luck, I found that the compatible version of this library that is version of react was 4.1.0.

It would be of great help with table with these specifications, thanks

Android support

This is a great plugin but having it work only on IOS makes it not as useful. Any plans on making this work on Android as well?

Thanks!

can't run

1、Duplicate interface definition for class 'RCTView'
2、Property has a previous declaration

"react": "15.4.1",
"react-native": "0.40.0",

Event for closing

Is there an event for blur? (when not selecting anything from the tooltip?)

Thanks.

Replace React.createClass with createReactClass (react 15.5+)

Chrome console output, on RN 0.46.2:

ExceptionsManager.js:71 Warning: React.createClass is no longer supported. Use a plain JavaScript class instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement. (https://fb.me/migrating-from-react-create-class)
reactConsoleErrorHandler | @ | ExceptionsManager.js:71
-- | -- | --
  | printWarning | @ | warning.js:36
  | warning | @ | warning.js:60
  | get | @ | react.development.js:2125
  | (anonymous) | @ | ToolTip.ios.js:24
  | loadModuleImplementation | @ | require.js:174
  | guardedLoadModule | @ | require.js:126
  | _require | @ | require.js:110
  | (anonymous) | @ | components.js:53
  | loadModuleImplementation | @ | require.js:174
  | guardedLoadModule | @ | require.js:126
  | _require | @ | require.js:110
  | (anonymous) | @ | index.ios.js:86
  | loadModuleImplementation | @ | require.js:174
  | guardedLoadModule | @ | require.js:119
  | _require | @ | require.js:110
  | (anonymous) | @ | redux-logger.js:1
  | executeApplicationScript | @ | debuggerWorker.js:40
  | (anonymous) | @ | debuggerWorker.js:65

A sample PR to fix: https://github.com/maxs15/react-native-modalbox/pull/148/files

Does not work when used over WebView.

I am working on a project where I need to show UIMenuController with custom option when user selects some html content in a WebView, when I place the webView inside ToolTip, it should work but It doesn't, Instead It won't even let WebView to Render.

Points to be noted:

  • I am Using alinz/react-native-webview-bridge Library for WebView and It pretty much works.
  • I want to add a custom option in the UIMenuController that performs some operation on the WebView contents.

Fails to build on 0.8.0

Receiving this error when trying to build:

/[...]/node_modules/react-native-tooltip/ToolTipMenu/RCTToolTipText.m:27:23: No visible @interface for 'RCTEventDispatcher' declares the selector 'sendTextEventWithType:reactTag:text:eventCount:'

Any ideas?

How can I style it like `TouchableWithoutFeedback`

I trigger the tooltip programmatically when user touches container. But the container will be "highlighted", even if I tried to set some properties like underlayColor='transparent'.
I wonder how can I remove the highlight effect.

callback for dismissing

Hi, author and contributors. Do you think it's possible that tooltip provides a callback invoked when it got dismissed? it's quite important when I try to combine it with redux and make it driven by state.

Undefined is Not an Object('evaluating ToolTipMenu.Show')

I have using this module getting this Like as below screen shot.
simulator screen shot jan 27 2017 12 06 21 pm

Undefined is Not an Object('evaluating ToolTipMenu.Show')

I have use this Code

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  Alert,
  AlertIos,
  Image,
  PixelRatio,
  Coordinates,
  TouchableOpacity,
  NativeModules,
  View
} from 'react-native';
var Dimensions = require('Dimensions');
var windowSize = Dimensions.get('window');
var ToolTip = require('react-native-tooltip');
var ToolTipMenu = NativeModules.ToolTipMenu;

export default class index extends Component {
  constructor(props) {
    super(props)
    this.state={
      xcor:null,
      ycor:null,
      corx:'',
      array:[],
      count: 0

    }
  }


handlePress(evt){
  var array =this.state.array
  var count = 0
  console.log("Coordinates",`x coord = ${evt.nativeEvent.locationX}`);
  console.log("Coordinates",`y coord = ${evt.nativeEvent.locationY}`);
  var cordinates = {
    "xcor":evt.nativeEvent.locationX,
    "ycor":evt.nativeEvent.locationY}
  array.push(cordinates)
  this.setState({
    array:array
  })

 /* this.setState({
    xcor:evt.nativeEvent.locationX,
    ycor:evt.nativeEvent.locationY,
    corx:evt.nativeEvent.locationX
  })*/
}

  render() {
    var array =[];
    if(this.state.array.length != 0){
      this.state.array.map((res)=>{
        array.push(
          <View style={styles.textinputContainer}>
          <ToolTip
            ref='theToolTip'
            actions={[
              {text: 'xcor', onPress: () => { this.setState({input: 'x pressed'}) }},
              {text: 'ycor', onPress: () => { this.setState({input: 'y pressed'}) }}
            ]}
            underlayColor='transparent'
            longPress={false}
            arrowDirection='down'
            style={styles.textinput}
          >
           <View style={{position:"relative",flex:1,left:res.xcor,top:res.ycor}}>
            <Image source={require('./logo.png')} style={{resizeMode:'cover',width:50,height:50}}>
            </Image>
          </View>
          </ToolTip>
        </View>
          
          )
      })
    }
    return (
      <View style={styles.container}>
      <View style={{position:'absolute'}}>
      <TouchableOpacity onPress={(evt) => this.handlePress(evt)}>
      <Image source={require('./back1.jpg')} style={{resizeMode:'cover',width:windowSize.width,height:windowSize.height}}>
        </Image>
         </TouchableOpacity>
      
        </View>
       
        {this.state.array.length != 0 ?(
          <View>
          {array}
      </View>
          ):(<View></View>)
         }
         
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
   
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  textinputContainer: {
    marginTop: 20,
    justifyContent: 'center',
    alignItems: 'center',
  },
  textinput: {
    width: 60,
    //marginVertical: 2,
    //marginHorizontal: 2,
    borderWidth: 1 / PixelRatio.get(),
    borderRadius: 5,
    borderColor: '#c7c7cc',
    padding: 2,
    fontSize: 14,
    backgroundColor: 'white',
  }
});

module.exports=index;

Tooltip disappearing after first tap

Hey there! First of all, thanks for this cool library. It has been working great.

We are having an issue when displaying the tooltip the first time after the user opens the app.
output

The tooltip dissapears that first time. After that, it works correctly:

output

The code is simple:

export default class ContextMenu extends React.PureComponent {
  componentWillUnmount() {
    if (this.ref) {
      this.ref.hideMenu();
      delete this.ref;
    }
  }

  setRef = (ref) => {
    if (!ref) {
      return;
    }

    this.ref = ref;
    if (ref) {
      setTimeout(() => {
        if (this.ref) {
          this.ref.showMenu();
        }
      }, 100);
    }
  }

  render() {
    const actions = getActions(this.props);

    return (
      <ToolTip
        actions={actions}
        ref={this.setRef}
      >
        <View />
      </ToolTip>
    );
  }
}

Note that we had to introduce that delay because the tooltip doesn't appear when placed in componentDidMount.
I tried to debug this, as I thought that a hideMenu() was being called, but it wasn't. showMenu() is called correctly and then the context menu disappears without a call to hideMenu().

Any help would be appreciated, thanks!

Field steals focus

Tapping on the element, steals the focus and dismisses the keyboard. Is there a way I can prevent this from happening? keyboardShouldPersistTaps={true} didn't work...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.