Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
Add hooks docs
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed Jun 6, 2020
1 parent bcb3fe6 commit 6412960
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 29 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@types/react-native": "^0.62.13",
"@types/react-test-renderer": "^16.9.2",
"babel-jest": "^26.0.1",
"eslint": "^7.1.0",
"eslint": "^7.2.0",
"eslint-plugin-simple-import-sort": "^5.0.3",
"jest": "^26.0.1",
"metro-react-native-babel-preset": "^0.59.0",
Expand Down
44 changes: 31 additions & 13 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,11 @@ acorn@^7.1.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf"
integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==

acorn@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe"
integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ==

ajv@^6.10.0, ajv@^6.10.2:
version "6.12.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.1.tgz#cce4d7dfcd62d3c57b1cd772e688eff5f5cd3839"
Expand Down Expand Up @@ -3181,6 +3186,14 @@ eslint-scope@^5.0.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-scope@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5"
integrity sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.0.0.tgz#7be1cc70f27a72a76cd14aa698bcabed6890e1cd"
Expand All @@ -3193,21 +3206,26 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==

eslint@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.1.0.tgz#d9a1df25e5b7859b0a3d86bb05f0940ab676a851"
integrity sha512-DfS3b8iHMK5z/YLSme8K5cge168I8j8o1uiVmFCgnnjxZQbCGyraF8bMl7Ju4yfBmCuxD7shOF7eqGkcuIHfsA==
eslint-visitor-keys@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa"
integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==

eslint@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6"
integrity sha512-B3BtEyaDKC5MlfDa2Ha8/D6DsS4fju95zs0hjS3HdGazw+LNayai38A25qMppK37wWGWNYSPOR6oYzlz5MHsRQ==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
chalk "^4.0.0"
cross-spawn "^7.0.2"
debug "^4.0.1"
doctrine "^3.0.0"
eslint-scope "^5.0.0"
eslint-scope "^5.1.0"
eslint-utils "^2.0.0"
eslint-visitor-keys "^1.1.0"
espree "^7.0.0"
eslint-visitor-keys "^1.2.0"
espree "^7.1.0"
esquery "^1.2.0"
esutils "^2.0.2"
file-entry-cache "^5.0.1"
Expand Down Expand Up @@ -3235,14 +3253,14 @@ eslint@^7.1.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

espree@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.0.0.tgz#8a7a60f218e69f120a842dc24c5a88aa7748a74e"
integrity sha512-/r2XEx5Mw4pgKdyb7GNLQNsu++asx/dltf/CI8RFi9oGHxmQFgvLbc5Op4U6i8Oaj+kdslhJtVlEZeAqH5qOTw==
espree@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.1.0.tgz#a9c7f18a752056735bf1ba14cb1b70adc3a5ce1c"
integrity sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw==
dependencies:
acorn "^7.1.1"
acorn "^7.2.0"
acorn-jsx "^5.2.0"
eslint-visitor-keys "^1.1.0"
eslint-visitor-keys "^1.2.0"

esprima@^4.0.0, esprima@^4.0.1:
version "4.0.1"
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flyerhq/react-native-keyboard-accessory-view",
"version": "1.0.8",
"version": "1.0.9",
"description": "Keyboard accessory (sticky) view for your React Native app. Supports interactive dismiss on iOS.",
"homepage": "https://github.com/flyerhq/react-native-keyboard-accessory-view#readme",
"main": "lib/index.js",
Expand All @@ -20,6 +20,9 @@
"files": [
"lib"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"compile": "rm -rf lib && tsc -p .",
"lint": "eslint .",
Expand All @@ -36,7 +39,7 @@
"@types/react-native": "^0.62.13",
"@types/react-test-renderer": "^16.9.2",
"babel-jest": "^26.0.1",
"eslint": "^7.1.0",
"eslint": "^7.2.0",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-simple-import-sort": "^5.0.3",
"jest": "^26.0.1",
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/useComponentSize.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as React from 'react'
import { LayoutChangeEvent } from 'react-native'

/**
* Calculates view's width & height based on the `onLayout` event.
* @example
* const [onLayout, size] = useComponentSize()
* ...
* <View onLayout={onLayout} /> // `size` will contain the size of this view
*/
export const useComponentSize = () => {
const [size, setSize] = React.useState({ height: 0, width: 0 })

Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useKeyboardDimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import {
} from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

/**
* Utility hook used to calculate keyboard dimensions.
*
* ⚠️ You shouldn't use this hook on the same screen with `KeyboardAccessoryView` component, unexpected behavior might occur
* @returns `keyboardEndPositionY` Keyboard's top line Y position
* @returns `keyboardHeight` Keyboard's height
* @returns `keyboardSafeAreaBottomInset` Additional space keyboard has when opened on devices with a safe area
*/
export const useKeyboardDimensions = () => {
const { bottom } = useSafeAreaInsets()
const { height } = useWindowDimensions()
Expand Down
12 changes: 12 additions & 0 deletions src/hooks/usePanResponder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import * as React from 'react'
import { PanResponder, Platform } from 'react-native'

/**
* Returns `panHandlers` used to calculate Y finger position.
*
* Used to support interactive dismiss on iOS, on Android `panHandlers` is an empty object.
*
* ⚠️ You shouldn't use this hook if you don't use interactive dismiss on iOS.
* @example
* // `positionY` will be passed to the `KeyboardAccessoryView` component
* const [panHandlers, positionY] = usePanResponder()
* ...
* <ScrollView {...panHandlers} />
*/
export const usePanResponder = () => {
const [positionY, setPositionY] = React.useState(0)

Expand Down
44 changes: 31 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,11 @@ acorn@^7.1.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf"
integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==

acorn@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe"
integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ==

ajv@^6.10.0, ajv@^6.10.2:
version "6.12.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.1.tgz#cce4d7dfcd62d3c57b1cd772e688eff5f5cd3839"
Expand Down Expand Up @@ -3243,6 +3248,14 @@ eslint-scope@^5.0.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-scope@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5"
integrity sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.0.0.tgz#7be1cc70f27a72a76cd14aa698bcabed6890e1cd"
Expand All @@ -3255,21 +3268,26 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==

eslint@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.1.0.tgz#d9a1df25e5b7859b0a3d86bb05f0940ab676a851"
integrity sha512-DfS3b8iHMK5z/YLSme8K5cge168I8j8o1uiVmFCgnnjxZQbCGyraF8bMl7Ju4yfBmCuxD7shOF7eqGkcuIHfsA==
eslint-visitor-keys@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa"
integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==

eslint@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6"
integrity sha512-B3BtEyaDKC5MlfDa2Ha8/D6DsS4fju95zs0hjS3HdGazw+LNayai38A25qMppK37wWGWNYSPOR6oYzlz5MHsRQ==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
chalk "^4.0.0"
cross-spawn "^7.0.2"
debug "^4.0.1"
doctrine "^3.0.0"
eslint-scope "^5.0.0"
eslint-scope "^5.1.0"
eslint-utils "^2.0.0"
eslint-visitor-keys "^1.1.0"
espree "^7.0.0"
eslint-visitor-keys "^1.2.0"
espree "^7.1.0"
esquery "^1.2.0"
esutils "^2.0.2"
file-entry-cache "^5.0.1"
Expand Down Expand Up @@ -3297,14 +3315,14 @@ eslint@^7.1.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

espree@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.0.0.tgz#8a7a60f218e69f120a842dc24c5a88aa7748a74e"
integrity sha512-/r2XEx5Mw4pgKdyb7GNLQNsu++asx/dltf/CI8RFi9oGHxmQFgvLbc5Op4U6i8Oaj+kdslhJtVlEZeAqH5qOTw==
espree@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.1.0.tgz#a9c7f18a752056735bf1ba14cb1b70adc3a5ce1c"
integrity sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw==
dependencies:
acorn "^7.1.1"
acorn "^7.2.0"
acorn-jsx "^5.2.0"
eslint-visitor-keys "^1.1.0"
eslint-visitor-keys "^1.2.0"

esprima@^4.0.0, esprima@^4.0.1:
version "4.0.1"
Expand Down

0 comments on commit 6412960

Please sign in to comment.