Skip to content

Commit 89a4760

Browse files
committed
chore: add example usage
1 parent 8d452cd commit 89a4760

File tree

4 files changed

+6626
-19
lines changed

4 files changed

+6626
-19
lines changed

example/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function (api) {
1717
},
1818
},
1919
],
20+
'react-native-reanimated/plugin',
2021
],
2122
};
2223
};

example/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
"web": "expo start --web"
1010
},
1111
"dependencies": {
12+
"@gorhom/portal": "^1.0.14",
1213
"expo": "~46.0.16",
1314
"expo-status-bar": "~1.4.0",
1415
"react": "18.0.0",
15-
"react-native": "0.69.6"
16+
"react-native": "0.69.6",
17+
"react-native-reanimated": "~2.9.1"
1618
},
1719
"devDependencies": {
1820
"@babel/core": "^7.12.9",
1921
"babel-plugin-module-resolver": "^4.1.0"
2022
},
2123
"private": true
22-
}
24+
}

example/src/App.tsx

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,75 @@
1-
import * as React from 'react';
1+
import React from 'react';
2+
import Tooltip from 'react-native-tooltiplize';
3+
import { PortalProvider } from '@gorhom/portal';
4+
import { View, TouchableOpacity, StyleSheet, Text } from 'react-native';
25

3-
import { StyleSheet, View, Text } from 'react-native';
4-
import { multiply } from 'react-native-tooltiplize';
6+
const App = () => {
7+
const [isVisible, toggle] = React.useReducer((state) => !state, false);
58

6-
export default function App() {
7-
const [result, setResult] = React.useState<number | undefined>();
8-
9-
React.useEffect(() => {
10-
multiply(3, 7).then(setResult);
9+
const renderContent = React.useCallback(() => {
10+
return (
11+
<TouchableOpacity style={styles.tooltipContainer} onPress={toggle}>
12+
<Text style={styles.tooltipText}>
13+
Welcome to React Native Tooltiplize 🥳
14+
</Text>
15+
</TouchableOpacity>
16+
);
1117
}, []);
1218

1319
return (
14-
<View style={styles.container}>
15-
<Text>Result: {result}</Text>
16-
</View>
20+
<PortalProvider>
21+
<View style={styles.container}>
22+
<Tooltip
23+
position="top"
24+
offset={8}
25+
renderContent={renderContent}
26+
isVisible={isVisible}
27+
withOverlay
28+
onDismiss={toggle}
29+
pointerStyle={styles.pointer}
30+
pointerColor="pink"
31+
>
32+
<TouchableOpacity onPress={toggle} style={styles.newFeature}>
33+
<Text style={styles.newFeatureText}>This is new cool feature</Text>
34+
</TouchableOpacity>
35+
</Tooltip>
36+
</View>
37+
</PortalProvider>
1738
);
18-
}
39+
};
40+
41+
export default App;
1942

2043
const styles = StyleSheet.create({
2144
container: {
2245
flex: 1,
23-
alignItems: 'center',
2446
justifyContent: 'center',
47+
alignItems: 'center',
48+
},
49+
tooltipContainer: {
50+
paddingHorizontal: 16,
51+
paddingVertical: 8,
52+
borderRadius: 8,
53+
shadowColor: '#000',
54+
shadowOffset: {
55+
width: 0,
56+
height: 2,
57+
},
58+
shadowOpacity: 0.1,
59+
shadowRadius: 12,
60+
backgroundColor: 'pink',
61+
},
62+
tooltipText: {
63+
fontSize: 12,
64+
color: 'black',
65+
},
66+
pointer: { width: 16, height: 8 },
67+
newFeature: {
68+
backgroundColor: 'white',
69+
padding: 16,
70+
borderRadius: 8,
2571
},
26-
box: {
27-
width: 60,
28-
height: 60,
29-
marginVertical: 20,
72+
newFeatureText: {
73+
fontSize: 16,
3074
},
3175
});

0 commit comments

Comments
 (0)