Skip to content

Commit

Permalink
refactor: use @gorhom/portal (#1)
Browse files Browse the repository at this point in the history
* refactor: use gorhom/portal

* chore: cleanup example

* chore: update readme

* fix: add containerStyle prop

* refactor: remove react-native-screens dependency

* refactor: set position in frame callback

* refactor: store element measured dimensions as shared value

* refactor: rename isDown to topHalfOfViewport

* fix: fix incorrect types
  • Loading branch information
johankasperi authored Nov 21, 2023
1 parent b640518 commit 61e58c9
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 245 deletions.
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,51 @@

Tooltip for React Native using React Native Reanimated and Modal

![Demo 1](./demo/1.gif)
![Demo 1](./demo.gif)

## Installation

```sh
npm install react-native-reanimated react-native-reanimated-tooltip
npm install react-native-reanimated @gorhom/portal react-native-reanimated-tooltip
```

## Usage

```ts
import { PortalProvider } from '@gorhom/portal';
import React from 'react';
import { Text, Button } from 'react-native';
import { Tooltip } from 'react-native-reanimated-tooltip';
import { FadeOut, FadeIn } from 'react-native-reanimated';

const [visible, setVisible] = React.useState(false);
<Tooltip
content={
<Text>Tooltip</Text>
}
visible={visible}
onPress={() => {
setVisible(false);
}}
entering={FadeIn}
exiting={FadeOut}
>
<Button
title="Toggle tooltip"
<PortalProvider>
<Tooltip
content={
<Text>Tooltip</Text>
}
visible={visible}
onPress={() => {
setVisible(true);
setVisible(false);
}}
/>
</Tooltip>
entering={FadeIn}
exiting={FadeOut}
>
<Button
title="Toggle tooltip"
onPress={() => {
setVisible(true);
}}
/>
</Tooltip>
</PortalProvider>

```

## Configuration

Check [TooltipProps](https://github.com/johankasperi/react-native-reanimated-tooltip/blob/efd333ae9dea7d1705a8828f2a82ba65338956f2/src/Tooltip.tsx#L29)

## Demo

![Demo 2](./demo/2.gif)
![Demo 3](./demo/3.gif)
![Demo 4](./demo/4.gif)
![Demo 5](./demo/5.gif)
![Demo 6](./demo/6.gif)

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demo/1.gif
Binary file not shown.
Binary file removed demo/2.gif
Binary file not shown.
Binary file removed demo/3.gif
Binary file not shown.
Binary file removed demo/4.gif
Binary file not shown.
Binary file removed demo/5.gif
Binary file not shown.
Binary file removed demo/6.gif
Binary file not shown.
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"web": "expo start --web"
},
"dependencies": {
"@gorhom/portal": "^1.0.14",
"expo": "~49.0.15",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
Expand Down
96 changes: 46 additions & 50 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,59 @@
import { PortalProvider } from '@gorhom/portal';
import React from 'react';

import { StyleSheet, View, Text, Button } from 'react-native';
import { FadeIn, FadeOut } from 'react-native-reanimated';
import { Tooltip } from 'react-native-reanimated-tooltip';

export default function App() {
const [activeTooltip, setActiveTooltip] = React.useState<1 | 2 | undefined>(
1
);
const [tooltip1Active, setTooltip1Active] = React.useState(false);
const [tooltip2Active, setTooltip2Active] = React.useState(false);

return (
<View style={styles.container}>
<View>
<Tooltip
content={
<>
<Text style={styles.tooltipHeadline}>Tooltip</Text>
<Text style={styles.tooltipBody}>Body</Text>
</>
}
visible={activeTooltip === 1}
onClose={() => {
setActiveTooltip(2);
}}
entering={FadeIn}
exiting={FadeOut.duration(1000)}
>
<Button
title="Toggle tooltip"
onPress={() => {
setActiveTooltip(1);
}}
/>
</Tooltip>
</View>
<View style={styles.tooltip2}>
<Tooltip
content={
<>
<Text style={styles.tooltipHeadline}>Tooltip 2</Text>
<Text style={styles.tooltipBody}>Body 2</Text>
</>
}
visible={activeTooltip === 2}
onClose={() => {
setActiveTooltip(undefined);
}}
entering={FadeIn}
exiting={FadeOut}
>
<Button
title="Toggle tooltip 2"
onPress={() => {
setActiveTooltip(2);
}}
/>
</Tooltip>
<PortalProvider>
<View style={styles.container}>
<View>
<Tooltip
content={
<>
<Text style={styles.tooltipHeadline}>Tooltip</Text>
<Text style={styles.tooltipBody}>Body</Text>
</>
}
visible={tooltip1Active}
entering={FadeIn}
exiting={FadeOut}
>
<Button
title="Toggle tooltip"
onPress={() => {
setTooltip1Active(!tooltip1Active);
}}
/>
</Tooltip>
</View>
<View style={styles.tooltip2}>
<Tooltip
content={
<>
<Text style={styles.tooltipHeadline}>Tooltip 2</Text>
<Text style={styles.tooltipBody}>Body 2</Text>
</>
}
visible={tooltip2Active}
entering={FadeIn}
exiting={FadeOut}
>
<Button
title="Toggle tooltip 2"
onPress={() => {
setTooltip2Active(!tooltip2Active);
}}
/>
</Tooltip>
</View>
</View>
</View>
</PortalProvider>
);
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"devDependencies": {
"@commitlint/config-conventional": "^17.0.2",
"@evilmartians/lefthook": "^1.5.0",
"@gorhom/portal": "^1.0.14",
"@react-native/eslint-config": "^0.72.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^28.1.2",
Expand All @@ -75,9 +76,10 @@
"@types/react": "17.0.21"
},
"peerDependencies": {
"@gorhom/portal": "^1",
"react": "*",
"react-native": "*",
"react-native-reanimated": "^2.0.0"
"react-native-reanimated": "^2"
},
"workspaces": [
"example"
Expand Down
Loading

0 comments on commit 61e58c9

Please sign in to comment.