|
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'; |
2 | 5 |
|
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); |
5 | 8 |
|
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 | + ); |
11 | 17 | }, []); |
12 | 18 |
|
13 | 19 | 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> |
17 | 38 | ); |
18 | | -} |
| 39 | +}; |
| 40 | + |
| 41 | +export default App; |
19 | 42 |
|
20 | 43 | const styles = StyleSheet.create({ |
21 | 44 | container: { |
22 | 45 | flex: 1, |
23 | | - alignItems: 'center', |
24 | 46 | 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, |
25 | 71 | }, |
26 | | - box: { |
27 | | - width: 60, |
28 | | - height: 60, |
29 | | - marginVertical: 20, |
| 72 | + newFeatureText: { |
| 73 | + fontSize: 16, |
30 | 74 | }, |
31 | 75 | }); |
0 commit comments