Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add placePreviousModalsBelowBackdrop prop #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"react-native": "0.66.4",
"react-native-builder-bob": "^0.18.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-screens": "^3.32.0",
"release-it": "^14.2.2",
"typescript": "^4.5.4"
},
Expand Down
19 changes: 12 additions & 7 deletions src/lib/ModalProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'use-memo-one'
import { BackHandler, Platform } from 'react-native'
import { FullWindowOverlay } from 'react-native-screens'
import React, { ReactNode, useEffect, useRef, useState } from 'react'

import type {
Expand Down Expand Up @@ -133,17 +134,21 @@ const ModalProvider = ({ children, stack }: Props) => {
}
}, [contextValue.stack.openedItems.size])

const modalStack = (
<ModalStack
{...contextValue}
clearListeners={clearListeners}
registerListener={registerListener}
eventListeners={modalEventListeners}
removeClosingAction={ModalState.removeClosingAction}
/>
)

return (
<ModalContext.Provider value={contextValue}>
<>
{children}
<ModalStack
{...contextValue}
clearListeners={clearListeners}
registerListener={registerListener}
eventListeners={modalEventListeners}
removeClosingAction={ModalState.removeClosingAction}
/>
{Platform.OS === 'ios' ? <FullWindowOverlay>{modalStack}</FullWindowOverlay> : modalStack}
</>
</ModalContext.Provider>
)
Expand Down
7 changes: 5 additions & 2 deletions src/lib/ModalStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ const ModalStack = <P extends ModalfyParams>(props: Props<P>) => {
.values()
.next().value
const hasPendingClosingAction = position === 1 && pendingClosingAction?.currentModalHash === stackItem.hash
const placePreviousModalsBelowBackdrop = stack.defaultOptions.placePreviousModalsBelowBackdrop

return (
<StackItem
{...props}
// @ts-ignore
stackItem={stackItem}
key={index}
zIndex={index + 1}
zIndex={placePreviousModalsBelowBackdrop && index < stack.openedItems.size - 1 ? -1 : index + 1}
position={position}
hideBackdrop={hideBackdrop}
openModal={(...args) => {
Expand Down Expand Up @@ -123,7 +124,9 @@ const ModalStack = <P extends ModalfyParams>(props: Props<P>) => {
stack.openedItems.size && backdropColor ? backdropColor : hasChangedBackdropColor ? 'transparent' : 'black'

return (
<TouchableWithoutFeedback onPress={onPress}>
<TouchableWithoutFeedback
onPress={onPress}
style={[stack.defaultOptions.placePreviousModalsBelowBackdrop && { zIndex: 0 }]}>
<Animated.View
style={[
styles.backdrop,
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ export interface ModalOptions {
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#pointereventsbehavior).
*/
pointerEventsBehavior?: 'auto' | 'none' | 'current-modal-only' | 'current-modal-none'
/**
* Determines if previous modals should be placed below the backdrop.
*
* @default false
*/
placePreviousModalsBelowBackdrop?: boolean
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const defaultOptions: ModalOptions = {
disableFlingGesture: false,
pointerEventsBehavior: 'auto',
backdropAnimationDuration: 300,
placePreviousModalsBelowBackdrop: false,
}

export { default as invariant } from './invariant'
Expand Down
6 changes: 6 additions & 0 deletions src/utils/validateDefaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function ({
transitionOptions,
pointerEventsBehavior,
backdropAnimationDuration,
placePreviousModalsBelowBackdrop,
}: ModalOptions = {}) {
invariant(
!backBehavior ||
Expand Down Expand Up @@ -58,4 +59,9 @@ export default function ({
}
}`,
)
invariant(
!placePreviousModalsBelowBackdrop ||
(placePreviousModalsBelowBackdrop && typeof placePreviousModalsBelowBackdrop === 'boolean'),
`placePreviousModalsBelowBackdrop should be a boolean in createModalStack(), you provided: ${placePreviousModalsBelowBackdrop}`,
)
}
57 changes: 41 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3694,12 +3694,12 @@ cosmiconfig@^5.0.5, cosmiconfig@^5.1.0:
js-yaml "^3.13.1"
parse-json "^4.0.0"

cross-fetch@^3.0.4:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
cross-fetch@^3.1.5:
version "3.1.8"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.8.tgz#0327eba65fd68a7d119f8fb2bf9334a1a7956f82"
integrity sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==
dependencies:
node-fetch "2.6.7"
node-fetch "^2.6.12"

cross-spawn@^6.0.0:
version "6.0.5"
Expand Down Expand Up @@ -4670,17 +4670,17 @@ fbjs-css-vars@^1.0.0:
integrity sha512-b2XGFAFdWZWg0phtAWLHCk836A1Xann+I+Dgd3Gk64MHKZO44FfoD1KxyvbSh0qZsIoXQGGlVztIY+oitJPpRQ==

fbjs@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-3.0.2.tgz#dfae08a85c66a58372993ce2caf30863f569ff94"
integrity sha512-qv+boqYndjElAJHNN3NoM8XuwQZ1j2m3kEvTgdle8IDjr6oUbkEpvABWtj/rQl3vq4ew7dnElBxL4YJAwTVqQQ==
version "3.0.5"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-3.0.5.tgz#aa0edb7d5caa6340011790bd9249dbef8a81128d"
integrity sha512-ztsSx77JBtkuMrEypfhgc3cI0+0h+svqeie7xHbh1k/IKdcydnvadp/mUaGgjAOXQmQSxsqgaRhS3q9fy+1kxg==
dependencies:
cross-fetch "^3.0.4"
cross-fetch "^3.1.5"
fbjs-css-vars "^1.0.0"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.30"
ua-parser-js "^1.0.35"

figures@^3.0.0:
version "3.2.0"
Expand Down Expand Up @@ -7328,13 +7328,20 @@ node-dir@^0.1.17:
dependencies:
minimatch "^3.0.2"

node-fetch@2.6.7, node-fetch@^2.2.0, node-fetch@^2.6.0, node-fetch@^2.6.7:
node-fetch@^2.2.0, node-fetch@^2.6.0, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.12:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down Expand Up @@ -8094,6 +8101,11 @@ react-devtools-core@^4.13.0:
shell-quote "^1.6.1"
ws "^7"

react-freeze@^1.0.0:
version "1.0.4"
resolved "https://registry.yarnpkg.com/react-freeze/-/react-freeze-1.0.4.tgz#cbbea2762b0368b05cbe407ddc9d518c57c6f3ad"
integrity sha512-r4F0Sec0BLxWicc7HEyo2x3/2icUTrRmDjaaRyzzn+7aDyFZliszMDOgLVwSnQnYENOlL1o569Ze2HZefk8clA==

react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.4:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down Expand Up @@ -8151,6 +8163,14 @@ react-native-gesture-handler@^1.10.3:
invariant "^2.2.4"
prop-types "^15.7.2"

react-native-screens@^3.32.0:
version "3.32.0"
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.32.0.tgz#47c3d2efc9cd5ed18af41b34efc8b46df05b87b4"
integrity sha512-wybqZAHX7v8ipOXhh90CqGLkBHw5JYqKNRBX7R/b0c2WQisTOgu0M0yGwBMM6LyXRBT+4k3NTGHdDbpJVpq0yQ==
dependencies:
react-freeze "^1.0.0"
warn-once "^0.1.0"

[email protected]:
version "0.66.4"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.66.4.tgz#bf89a5fb18bd23046d889fb4de4ea2822a4d7805"
Expand Down Expand Up @@ -8755,7 +8775,7 @@ set-value@^2.0.0, set-value@^2.0.1:
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=
integrity sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==

[email protected]:
version "1.2.0"
Expand Down Expand Up @@ -9465,10 +9485,10 @@ typescript@^4.5.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3"
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==

ua-parser-js@^0.7.30:
version "0.7.33"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.33.tgz#1d04acb4ccef9293df6f70f2c3d22f3030d8b532"
integrity sha512-s8ax/CeZdK9R/56Sui0WM6y9OFREJarMRHqLB2EwkovemBxNQ+Bqu8GAsUnVcXKgphb++ghr/B2BZx4mahujPw==
ua-parser-js@^1.0.35:
version "1.0.38"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.38.tgz#66bb0c4c0e322fe48edfe6d446df6042e62f25e2"
integrity sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ==

uglify-es@^3.1.9:
version "3.3.9"
Expand Down Expand Up @@ -9718,6 +9738,11 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.12"

warn-once@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.1.1.tgz#952088f4fb56896e73fd4e6a3767272a3fccce43"
integrity sha512-VkQZJbO8zVImzYFteBXvBOZEl1qL175WH8VmZcxF2fZAoudNhNDvHi+doCaAEdU2l2vtcIwa2zn0QK5+I1HQ3Q==

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
Expand Down