Skip to content

Commit f616900

Browse files
committed
feat: tooltip 2 is ready to publish and test
1 parent 90f0029 commit f616900

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+65677
-8514
lines changed

README.md

Lines changed: 94 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,51 @@
1-
<img alt="React Native Typescript Library Starter" src="assets/logo.png" width="1050"/>
1+
<img alt="React Native Tooltip 2" src="assets/logo.png" width="1050"/>
22

3-
[![Battle Tested ✅](https://img.shields.io/badge/-Battle--Tested%20%E2%9C%85-03666e?style=for-the-badge)](https://github.com/WrathChaos/react-native-typescript-library-starter)
3+
[![Battle Tested ✅](https://img.shields.io/badge/-Battle--Tested%20%E2%9C%85-03666e?style=for-the-badge)](https://github.com/WrathChaos/react-native-tooltip-2)
44

5-
[![React Native Typescript Library Starter](https://img.shields.io/badge/-Extremely%20easy%20to%20create%20a%20React%20Native%20Component%20Library%20with%20both%20Stateful%20and%20Functional%20Component%20Examples-orange?style=for-the-badge)](https://github.com/WrathChaos/react-native-typescript-library-starter)
5+
[![React Native Tooltip 2](https://img.shields.io/badge/-Customizable%2C%20easy%20to%20use%20tooltip%20for%20React%20Native-orange?style=for-the-badge)](https://github.com/WrathChaos/react-native-tooltip-2)
66

7-
[![npm version](https://img.shields.io/npm/v/react-native-typescript-library-starter.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-typescript-library-starter)
8-
[![npm](https://img.shields.io/npm/dt/react-native-typescript-library-starter.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-typescript-library-starter)
7+
[![npm version](https://img.shields.io/npm/v/react-native-tooltip-2.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-tooltip-2)
8+
[![npm](https://img.shields.io/npm/dt/react-native-tooltip-2.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-tooltip-2)
99
![Platform - Android and iOS](https://img.shields.io/badge/platform-Android%20%7C%20iOS-blue.svg?style=for-the-badge)
1010
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
1111
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)
1212

1313
<p align="center">
14-
<img alt="React Native Typescript Library Starter"
14+
<img alt="React Native Tooltip 2"
1515
src="assets/Screenshots/typescript.jpg" />
1616
</p>
1717

18-
## Library Usage
19-
20-
- `npm i`
21-
- `npm run husky:setup`
22-
- Delete example folder
23-
- Delete build folder
24-
- Make your own library into the `lib` folder
25-
- Change package.json
26-
- Change README for your own documentation
27-
- `npm run build`
28-
29-
```
30-
> react-native-typescript-library-starter@0.1.0 build /Users/kuray/Coursion/MyLibraries/ReactNative/react-native-typescript-library-starter
31-
> cd lib && tsc && cp ../package.json ../build/dist/ && Echo Build completed!
32-
33-
Build completed!
34-
```
35-
36-
- Test your build/dist into the new project
37-
- Finally, time to npm publish :)
38-
39-
### Below part is for Documentation ! Remove above Library Usage
40-
4118
# Installation
4219

4320
Add the dependency:
4421

4522
```bash
46-
npm i react-native-typescript-library-starter
47-
```
48-
49-
## Peer Dependencies
50-
51-
<h5><i>IMPORTANT! You need install them</i></h5>
52-
53-
```js
54-
"react": ">= 16.x.x",
55-
"react-native": ">= 0.55.x",
23+
npm i react-native-tooltip-2
5624
```
5725

5826
# Usage
5927

6028
## Import
6129

62-
```jsx
63-
import MyComponent from "react-native-typescript-library-starter";
30+
```tsx
31+
import Tooltip from "react-native-tooltip-2";
6432
```
6533

6634
## Fundamental Usage
6735

68-
```jsx
69-
<MyComponent />
36+
```tsx
37+
<Tooltip
38+
isVisible={toolTipVisible}
39+
content={<Text>Check this out!</Text>}
40+
placement={Placement.TOP}
41+
backgroundStyle={{backgroundColor: 'transparent'}}
42+
onClose={() => setToolTipVisible(false)}>
43+
<Pressable
44+
style={styles.button}
45+
onPress={() => setToolTipVisible(true)}>
46+
<Text>Press me</Text>
47+
</Pressable>
48+
</Tooltip>
7049
```
7150

7251
## Example Project 😍
@@ -75,44 +54,96 @@ You can checkout the example project 🥰
7554

7655
Simply run
7756

78-
- `npm i`
57+
- `npm i && npx pod-install`
7958
- `react-native run-ios/android`
8059

8160
should work of the example project.
8261

83-
# Configuration - Props
62+
### How it works
8463

85-
## Fundamentals
64+
The tooltip wraps an element _in place_ in your React Native rendering. When it renders, it measures the location of the element, using React Native's
65+
[measure](https://facebook.github.io/react-native/docs/direct-manipulation.html#measurecallback). When the tooltip is displayed, it renders a _copy_ of the wrapped element positioned absolutely on the screen at the coordinates returned after measuring ([see `TooltipChildrenContext` below](#tooltipchildrencontext) if you need to tell the difference between the _copy_ and the _original_ element). This allows you to touch the element in the tooltip modal rendered above your current screen.
8666

87-
| Property | Type | Default | Description |
88-
| ----------- | :----: | :-------: | --------------------- |
89-
| title | string | undefined | change the title |
90-
| description | string | undefined | change the descrition |
67+
### Props
9168

92-
## Customization (Optionals)
69+
| Prop name | Type | Default value | Description |
70+
| ---------------- | ---------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71+
| accessible | bool| true | Set this to `false` if you do not want the root touchable element to be accessible. [See docs on accessible here](https://reactnative.dev/docs/accessibility#accessibility-properties)
72+
| allowChildInteraction | bool| true | By default, the user can touch and interact with the child element. When this prop is false, the user cannot interact with the child element while the tooltip is visible. |
73+
| arrowSize | `Size` | { width: 16, height: 8 } | The dimensions of the arrow on the bubble pointing to the highlighted element |
74+
| backgroundColor | string | 'rgba(0,0,0,0.5)' | Color of the fullscreen background beneath the tooltip. **_Overrides_** the `backgroundStyle` prop |
75+
| childContentSpacing | number | 4 | The distance between the tooltip-rendered child and the arrow pointing to it |
76+
| closeOnChildInteraction | bool | true | When child interaction is allowed, this prop determines if `onClose` should be called when the user interacts with the child element. Default is true (usually means the tooltip will dismiss once the user touches the element highlighted) |
77+
| closeOnContentInteraction | bool | true | this prop determines if `onClose` should be called when the user interacts with the content element. Default is true (usually means the tooltip will dismiss once the user touches the content element) |
78+
| content | function/Element | `<View />` | This is the view displayed in the tooltip popover bubble |
79+
| displayInsets | object | { top: 24, bottom: 24, left: 24, right: 24 } | The number of pixels to inset the tooltip on the screen (think of it like padding). The tooltip bubble should never render outside of these insets, so you may need to adjust your `content` accordingly |
80+
| disableShadow | bool | false | When true, tooltips will not appear elevated. Disabling shadows will remove the warning: `RCTView has a shadow set but cannot calculate shadow efficiently` on IOS devices. |
81+
| isVisible | bool | false | When true, tooltip is displayed | |
82+
| onClose | function | null | Callback fired when the user taps the tooltip background overlay |
83+
| placement | string | "top" \| "center" | Where to position the tooltip - options: `top, bottom, left, right, center`. Default is `top` for tooltips rendered with children Default is `center` for tooltips rendered without children. <br><br>NOTE: `center` is only available with a childless placement, and the content will be centered within the bounds defined by the `displayInsets`. |
84+
| showChildInTooltip | bool | true | Set this to `false` if you do NOT want to display the child alongside the tooltip when the tooltip is visible |
85+
| supportedOrientations | array | ["portrait", "landscape"] | This prop allows you to control the supported orientations the tooltip modal can be displayed. It correlates directly with [the prop for React Native's Modal component](https://facebook.github.io/react-native/docs/modal#supportedorientations) (has no effect if `useReactNativeModal` is false) |
86+
| topAdjustment | number | 0 | Value which provides additional vertical offest for the child element displayed in a tooltip. Commonly set to: `Platform.OS === 'android' ? -StatusBar.currentHeight : 0` due to an issue with React Native's measure function on Android
87+
| horizontalAdjustment | number | 0 | Value which provides additional horizontal offest for the child element displayed in a tooltip. This is useful for adjusting the horizontal positioning of a highlighted child element if needed
88+
| useInteractionManager | bool | false | Set this to true if you want the tooltip to wait to become visible until the callback for `InteractionManager.runAfterInteractions` is executed. Can be useful if you need to wait for navigation transitions to complete, etc. [See docs on InteractionManager here](https://facebook.github.io/react-native/docs/interactionmanager)
89+
| useReactNativeModal | bool| true | By default, this library uses a `<Modal>` component from React Native. If you need to disable this, and simply render an absolutely positioned full-screen view, set `useReactNativeModal={false}`. This is especially useful if you desire to render a Tooltip while you have a different `Modal` rendered.
9390

94-
| Property | Type | Default | Description |
95-
| -------------- | :-------: | :-------: | ---------------------------------------------------------------------- |
96-
| enableButton | boolean | false | let you enable the button (must use it for button) |
97-
| onPress | function | undefined | set your own logic for the button functionality when it is pressed |
98-
| buttonText | string | undefined | change the button's text |
99-
| style | ViewStyle | default | set or override the style object for the main container |
100-
| buttonStyle | ViewStyle | default | set or override the style object for the button style |
101-
| ImageComponent | Image | default | set your own component instead of default react-native Image component |
91+
### Style Props
92+
93+
The tooltip styles should work out-of-the-box for most use cases, however should you need you can customize the styles of the tooltip using these props.
94+
95+
| Prop name | Effect |
96+
| -------------------- | ------------------------------------------------------------------------------- |
97+
| arrowStyle | Styles the triangle that points to the called out element |
98+
| backgroundStyle | Styles the overlay view that sits behind the tooltip, but over the current view |
99+
| childrenWrapperStyle | Styles the view that wraps cloned children |
100+
| contentStyle | Styles the content wrapper that surrounds the `content` element |
101+
| tooltipStyle | Styles the tooltip that wraps the arrow and content elements |
102+
103+
### Class definitions for props
104+
105+
* `Size` is an object with properties: `{ width: number, height: number }`
106+
107+
### TooltipChildrenContext
108+
109+
[React Context](https://reactjs.org/docs/context.html) that can be used to distinguish "real" children rendered inside parent's layout from their copies rendered inside tooltip's modal. The duplicate child rendered in the tooltip modal is wrapped in a Context.Provider which provides object with prop `tooltipDuplicate` set to `true`, so informed decisions may be made, if necessary, based on where the child rendered.
110+
111+
```js
112+
import Tooltip, { TooltipChildrenContext } from 'react-native-walkthrough-tooltip';
113+
...
114+
<Tooltip>
115+
<ComponentA />
116+
<ComponentB>
117+
<TooltipChildrenContext.Consumer>
118+
{({ tooltipDuplicate }) => (
119+
// Will only assign a ref to the original component
120+
<FlatList {...(!tooltipDuplicate && { ref: this.listRef })} />
121+
)}
122+
</TooltipChildrenContext.Consumer>
123+
</ComponentB>
124+
</Tooltip>
125+
```
126+
127+
## Credits
128+
129+
This library is a fork of [react-native-walkthrough-tooltip](https://github.com/jasongaare/react-native-walkthrough-tooltip)
130+
- Full typescript re-written
131+
- Much better types and props
132+
- Better customizability
102133

103134
## Future Plans
104135

105136
- [x] ~~LICENSE~~
137+
- [ ] Code separation rely on **separation of concern(SoC)**
138+
- [ ] Code cleanup and refactoring
139+
- [ ] Better README and documentation
106140
- [ ] Write an article about the lib on Medium
107141

108-
# Change Log
109-
110-
Change log will be here !
111142

112143
## Author
113144

114145
FreakyCoder, kurayogun@gmail.com
115146

116147
## License
117148

118-
React Native Typescript Library Starter is available under the MIT license. See the LICENSE file for more info.
149+
React Native Tooltip 2 is available under the MIT license. See the LICENSE file for more info.

example/.buckconfig

Lines changed: 0 additions & 6 deletions
This file was deleted.

example/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

example/.flowconfig

Lines changed: 0 additions & 73 deletions
This file was deleted.

example/.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/.gitignore

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.env.local
2324

2425
# Android/IntelliJ
2526
#
@@ -28,32 +29,35 @@ build/
2829
.gradle
2930
local.properties
3031
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
3136

3237
# node.js
3338
#
3439
node_modules/
3540
npm-debug.log
3641
yarn-error.log
3742

38-
# BUCK
39-
buck-out/
40-
\.buckd/
41-
*.keystore
42-
!debug.keystore
43-
4443
# fastlane
4544
#
4645
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
4746
# screenshots whenever they are needed.
4847
# For more information about the recommended setup visit:
4948
# https://docs.fastlane.tools/best-practices/source-control/
5049

51-
*/fastlane/report.xml
52-
*/fastlane/Preview.html
53-
*/fastlane/screenshots
50+
**/fastlane/report.xml
51+
**/fastlane/Preview.html
52+
**/fastlane/screenshots
53+
**/fastlane/test_output
5454

5555
# Bundle artifact
5656
*.jsbundle
5757

58-
# CocoaPods
58+
# Ruby / CocoaPods
5959
/ios/Pods/
60+
/vendor/bundle/
61+
62+
# Temporary files created by Metro to check the health of the file watcher
63+
.metro-health-check*

example/.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

example/.prettierrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
24
bracketSpacing: false,
3-
jsxBracketSameLine: true,
45
singleQuote: true,
56
trailingComma: 'all',
67
};

example/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.6

0 commit comments

Comments
 (0)