npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-highlight-tooltip

v2.0.6

Published

A higher-order component for showing tooltips on focused components in React Native.

Downloads

163

Readme

React Native Highlight Tooltip npm

React Native Highlight Tooltip let's you highlights specific UI components by simply taking a reference (ref) of the component.

Please Note: This package might not work as expected with some components like FlatList, SectionList, and others due to their unique rendering behaviors. To ensure proper highlighting, wrap these components in a View and provide the reference (ref) of the View instead.

Table of Contents

Installation

npm i react-native-highlight-tooltip

Screenshot

Example Usage

import {
  View,
  Alert,
  FlatList,
  StatusBar,
  StyleSheet,
  SafeAreaView,
} from 'react-native';
import {articles} from '../5-instagram-feed/data';
import HighlightTooltip from 'react-native-highlight-tooltip';
import React, {useEffect, useRef, useState} from 'react';
import Header from '../5-instagram-feed/components/Header';
import Article from '../5-instagram-feed/components/Article';
import Stories from '../5-instagram-feed/components/Stories';

export default function App() {
  const [tooltipText, setTooltipText] = useState(null);
  const [tooltipPosition, setTooltipPosition] = useState(null);
  const [highlightRef, setHighlightRef] = useState(null);
  const [highlightVisible, setHighlightVisible] = useState(false);

 
  const [demoStep, setDemoStep] = useState('stories');

  // reference of components which you wanna highlight
  const stories = useRef(null);
  const posts = useRef(null);
  const camera = useRef(null);
  const message = useRef(null);

  const handleAppWalkthrough = (reference, tipText, tipPosition) => {
    setHighlightRef(reference);
    setTooltipText(tipText);
    setTooltipPosition(tipPosition);
  };

  useEffect(() => {
    if (highlightVisible === false) {
      Alert.alert('Demo', 'Start App Walkthrough', [
        {
          text: 'OK',
          onPress: () => {
            setHighlightVisible(true);
            handleAppWalkthrough(stories, 'This are Stories', 'bottom');
          },
        },
      ]);
    }
  }, []);

  return (
    <SafeAreaView style={styles.container}>
      <StatusBar />
      <View style={styles.header}>
        <Header cameraRef={camera} messageRef={message} />
      </View>

      <View ref={stories} style={styles.stories}>
        <Stories />
      </View>

      <View ref={posts}>
        <FlatList
          data={articles}
          renderItem={({item}) => <Article item={item} />}
          keyExtractor={item => item.id.toString()}
          showsVerticalScrollIndicator={false}
        />
      </View>

      <HighlightTooltip
        tooltipText={tooltipText}
        visible={highlightVisible}
        highlightRef={highlightRef}
        tooltipPosition={tooltipPosition}
        onPressHighlight={() => {
          if (demoStep === 'stories') {
            handleAppWalkthrough(posts, 'This are Posts', 'top');
            setDemoStep('posts');
          } else if (demoStep === 'posts') {
            handleAppWalkthrough(
              {
                reference: camera,
                style: {
                  margin: 10,
                },
              },
              'uploads Photos from here',
              'bottomRight',
            );
            setDemoStep('camera');
          } else if (demoStep === 'camera') {
            handleAppWalkthrough(
              {
                reference: message,
                style: {
                  margin: 10,
                },
              },
              'Open Your Messages From Here',
              'bottomLeft',
            );
            setDemoStep('message');
          } else if (demoStep === 'message') {
            Alert.alert('Demo', 'End Demo', [
              {
                text: 'OK',
                onPress: () => {
                  setHighlightVisible(false);
                },
              },
            ]);
          }
        }}
        arrowOffset={8}
        offset={8}
        customTooltip={{
          style: {
            height: 100,
            width: 200,
            paddingHorizontal: 5,
            justifyContent: 'center',
            alignItems: 'center',
            backgroundColor: 'black',
            borderRadius: 10,
          },
          textStyle: {
            color: 'white',
            fontSize: 16,
          },
          message: tooltipText,
        }}
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  header: {
    height: 44,
    flexDirection: 'row',
    borderBottomWidth: 1,
    alignItems: 'center',
    paddingHorizontal: 16,
    borderBottomColor: '#dbdbdb',
    justifyContent: 'space-between',
  },
  stories: {
    height: 104,
    paddingLeft: 8,
    paddingVertical: 10,
    borderBottomWidth: 1,
    backgroundColor: '#fafafa',
    borderBottomColor: '#dbdbdb',
  },
});

Props

| Prop name | Type | Default value | Description | | ---------------- | ---------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | visible | bool | false |Determines if the HighlightTooltip is visible. This prop is required. | | | | highlightRef | ref of comp | null | A reference to the component you want to highlight. Alternatively, you can pass an object like { reference: ref, style: { margin: 10 } }. The style property allows you to add extra space around the highlighted area. accepted properties are margin, marginLeft, marginTop, marginRight, and marginBottom. For example, setting margin: 10 will increase the highlighted area by 10 pixels around the component. see Example Usage | | | | tooltipText | string | none |The text to be displayed in the tooltip. This will only be used if customTooltip is not provided. | | | | tooltipPosition | string | top |Defines the position of the tooltip relative to the highlighted component. Acceptable values include: 'topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'top', and 'bottom'. | | | | offset | number | 0 |The offset of the tooltip from its default position, useful for fine-tuning the tooltip’s location. works only with: 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'. | | | | arrowOffset | number | 0 |The offset of the arrow on the tooltip from its default position. works only with: 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'. | | | | overlayColor | string | rgba(0, 0, 0, 0.5) |The color of the overlay surrounding the highlighted component. | | | | onPressHighlight | function | null |Callback function triggered when the highlighted component is pressed. | | | | onRequestClose | function | null |Callback function triggered on hardware back press when the HighlightTooltip is visible. | | | | customTooltip | object | null |Custom tooltip content and style. Must include style with height and width properties. The message property is required to display text. textStyle for message style. see Example Usage | | |

How It Works

Internally, react-native-highlight-tooltip leverages React's ref system to identify and measure the position and dimensions of the component you want to highlight. When a ref is passed to the HighlightTooltip component, it dynamically calculates the position of the tooltip relative to the highlighted component. The component overlays a semi-transparent backdrop across the screen, darkening everything except the highlighted area, which remains fully visible. The tooltip is then positioned near the highlighted component, with an arrow pointing towards it. This creates a clear visual focus on the component. The package also manages the touch and interaction behavior of the highlighted component, allowing you to control whether users can interact with it while the tooltip is displayed.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue. Feel free to fork the repository and submit a pull request.