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

feature: add blur props #114

Open
wants to merge 1 commit 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
30 changes: 20 additions & 10 deletions src/components/backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import React, { memo } from 'react';
import { StyleSheet } from 'react-native';
import {
TapGestureHandler,
TapGestureHandlerGestureEvent,
} from 'react-native-gesture-handler';
import Animated, {
useAnimatedGestureHandler,
useAnimatedProps,
useAnimatedStyle,
withDelay,
withTiming,
} from 'react-native-reanimated';
import {
TapGestureHandler,
TapGestureHandlerGestureEvent,
} from 'react-native-gesture-handler';

// Components
import { BlurView } from 'expo-blur';

// Utils
import { styles } from './styles';
import {
CONTEXT_MENU_STATE,
HOLD_ITEM_TRANSFORM_DURATION,
IS_IOS,
WINDOW_HEIGHT,
} from '../../constants';
import { useInternal } from '../../hooks';
import {
BACKDROP_LIGHT_BACKGROUND_COLOR,
BACKDROP_DARK_BACKGROUND_COLOR,
BACKDROP_LIGHT_BACKGROUND_COLOR,
} from './constants';
import { useInternal } from '../../hooks';
import { styles } from './styles';

// Types
import { BackdropProps } from './types';

const AnimatedBlurView = IS_IOS
? Animated.createAnimatedComponent(BlurView)
Expand All @@ -40,7 +43,10 @@ type Context = {
};
};

const BackdropComponent = () => {
const BackdropComponent = ({
enableBlur = true,
blurIntensity = 100,
}: BackdropProps) => {
const { state, theme } = useInternal();

const tapGestureEvent = useAnimatedGestureHandler<
Expand Down Expand Up @@ -95,7 +101,11 @@ const BackdropComponent = () => {
const animatedContainerProps = useAnimatedProps(() => {
return {
intensity: withTiming(
state.value === CONTEXT_MENU_STATE.ACTIVE ? 100 : 0,
state.value === CONTEXT_MENU_STATE.ACTIVE
? enableBlur
? blurIntensity
: 0
: 0,
{
duration: HOLD_ITEM_TRANSFORM_DURATION,
}
Expand All @@ -109,7 +119,7 @@ const BackdropComponent = () => {
? BACKDROP_LIGHT_BACKGROUND_COLOR
: BACKDROP_DARK_BACKGROUND_COLOR;

return { backgroundColor };
return { backgroundColor: enableBlur ? backgroundColor : 'transparent' };
}, [theme]);

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/backdrop/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Backdrop } from './Backdrop';
export type { BackdropProps } from './types';
18 changes: 18 additions & 0 deletions src/components/backdrop/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type BackdropProps = {
/**
* Blur enabled. Optional.
* @type "true" | "false"
* @default "true"
* @examples
* enableBlur="false"
*/
enableBlur?: boolean;
/**
* Blur radius. Optional.
* @type number
* @default 100
* @examples
* blurIntensity={20}
*/
blurIntensity?: number;
};
4 changes: 3 additions & 1 deletion src/components/provider/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export let AnimatedIcon: any;

const ProviderComponent = ({
children,
enableBlur,
blurIntensity,
theme: selectedTheme,
iconComponent,
safeAreaInsets,
Expand Down Expand Up @@ -92,7 +94,7 @@ const ProviderComponent = ({
<InternalContext.Provider value={internalContextVariables}>
<PortalProvider>
{children}
<Backdrop />
<Backdrop enableBlur={enableBlur} blurIntensity={blurIntensity} />
<Menu />
</PortalProvider>
</InternalContext.Provider>
Expand Down
4 changes: 3 additions & 1 deletion src/components/provider/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface HoldMenuProviderProps {
import type { BackdropProps } from '../backdrop';

export interface HoldMenuProviderProps extends BackdropProps {
/**
* Theme of hold menu. Effects to backdrop and context menu styles. Optional.
* @type "light" | "dark"
Expand Down
38 changes: 33 additions & 5 deletions website/docs/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ Values:
<HoldMenuProvider theme={"dark"}>
```

### `enableBlur`

Enable or disable the backdrop blur

#### Example

```tsx
<HoldMenuProvider enableBlur={false}>
```

| type | default | required |
| ------- | ------- | -------- |
| boolean | true | NO |

### `blurIntensity`

the intensity of the backdrop blur

#### Example

```tsx
<HoldMenuProvider blurIntensity={20}>
```

| type | default | required |
| ------ | ------- | -------- |
| number | 100 | NO |

### `safeAreaInsets`

Set object of safe area inset values to prevent the menu to be opened under the unsafe area
Expand All @@ -56,7 +84,7 @@ Fires callback when menu is opened

```tsx
const onOpen = useCallback(() => {
console.log('App onOpen')
console.log('App onOpen');
}, []);

<HoldMenuProvider onOpen={onOpen} />;
Expand All @@ -70,7 +98,7 @@ Fires callback when menu is opened

```tsx
const onClose = useCallback(() => {
console.log('App onClose')
console.log('App onClose');
}, []);

<HoldMenuProvider onClose={onClose} />;
Expand Down Expand Up @@ -244,9 +272,9 @@ Set true if you want to close menu when tap to HoldItem

Set delay before long tap will activate gesture. May be useful to increase this value in lists

| type | default | required |
| ------- | ------- | -------- |
| number | 150 | NO |
| type | default | required |
| ------ | ------- | -------- |
| number | 150 | NO |

#### Example

Expand Down