Fix share button not working for some users (#5849)
* fix share button * Revert "fix share button" This reverts commit 3521c241729dc9bbe3dd7b62fc6e3e61e011cdf9. * tweak * Clean up context --------- Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
@@ -10,3 +10,23 @@ export const Context = React.createContext<ContextType>({
|
|||||||
export const ItemContext = React.createContext<ItemContextType>({
|
export const ItemContext = React.createContext<ItemContextType>({
|
||||||
disabled: false,
|
disabled: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export function useMenuContext() {
|
||||||
|
const context = React.useContext(Context)
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useMenuContext must be used within a Context.Provider')
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useMenuItemContext() {
|
||||||
|
const context = React.useContext(ItemContext)
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useMenuItemContext must be used within a Context.Provider')
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import {atoms as a, useTheme} from '#/alf'
|
|||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
import {Context, ItemContext} from '#/components/Menu/context'
|
import {
|
||||||
|
Context,
|
||||||
|
ItemContext,
|
||||||
|
useMenuContext,
|
||||||
|
useMenuItemContext,
|
||||||
|
} from '#/components/Menu/context'
|
||||||
import {
|
import {
|
||||||
ContextType,
|
ContextType,
|
||||||
GroupProps,
|
GroupProps,
|
||||||
@@ -25,10 +30,6 @@ export {
|
|||||||
useDialogControl as useMenuControl,
|
useDialogControl as useMenuControl,
|
||||||
} from '#/components/Dialog'
|
} from '#/components/Dialog'
|
||||||
|
|
||||||
export function useMemoControlContext() {
|
|
||||||
return React.useContext(Context)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Root({
|
export function Root({
|
||||||
children,
|
children,
|
||||||
control,
|
control,
|
||||||
@@ -47,7 +48,7 @@ export function Root({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
||||||
const {control} = React.useContext(Context)
|
const context = useMenuContext()
|
||||||
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
||||||
const {
|
const {
|
||||||
state: pressed,
|
state: pressed,
|
||||||
@@ -57,14 +58,14 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
|||||||
|
|
||||||
return children({
|
return children({
|
||||||
isNative: true,
|
isNative: true,
|
||||||
control,
|
control: context.control,
|
||||||
state: {
|
state: {
|
||||||
hovered: false,
|
hovered: false,
|
||||||
focused,
|
focused,
|
||||||
pressed,
|
pressed,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
onPress: control.open,
|
onPress: context.control.open,
|
||||||
onFocus,
|
onFocus,
|
||||||
onBlur,
|
onBlur,
|
||||||
onPressIn,
|
onPressIn,
|
||||||
@@ -82,7 +83,7 @@ export function Outer({
|
|||||||
showCancel?: boolean
|
showCancel?: boolean
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
}>) {
|
}>) {
|
||||||
const context = React.useContext(Context)
|
const context = useMenuContext()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -105,7 +106,7 @@ export function Outer({
|
|||||||
|
|
||||||
export function Item({children, label, style, onPress, ...rest}: ItemProps) {
|
export function Item({children, label, style, onPress, ...rest}: ItemProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {control} = React.useContext(Context)
|
const context = useMenuContext()
|
||||||
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
||||||
const {
|
const {
|
||||||
state: pressed,
|
state: pressed,
|
||||||
@@ -121,10 +122,9 @@ export function Item({children, label, style, onPress, ...rest}: ItemProps) {
|
|||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
onPress={async e => {
|
onPress={async e => {
|
||||||
await onPress(e)
|
context.control.close(() => {
|
||||||
if (!e.defaultPrevented) {
|
onPress?.(e)
|
||||||
control?.close()
|
})
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onPressIn={e => {
|
onPressIn={e => {
|
||||||
onPressIn()
|
onPressIn()
|
||||||
@@ -156,7 +156,7 @@ export function Item({children, label, style, onPress, ...rest}: ItemProps) {
|
|||||||
|
|
||||||
export function ItemText({children, style}: ItemTextProps) {
|
export function ItemText({children, style}: ItemTextProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {disabled} = React.useContext(ItemContext)
|
const {disabled} = useMenuItemContext()
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
@@ -177,7 +177,7 @@ export function ItemText({children, style}: ItemTextProps) {
|
|||||||
|
|
||||||
export function ItemIcon({icon: Comp}: ItemIconProps) {
|
export function ItemIcon({icon: Comp}: ItemIconProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {disabled} = React.useContext(ItemContext)
|
const {disabled} = useMenuItemContext()
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
size="lg"
|
size="lg"
|
||||||
@@ -223,7 +223,7 @@ export function Group({children, style}: GroupProps) {
|
|||||||
|
|
||||||
function Cancel() {
|
function Cancel() {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {control} = React.useContext(Context)
|
const context = useMenuContext()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -231,7 +231,7 @@ function Cancel() {
|
|||||||
size="small"
|
size="small"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onPress={() => control.close()}>
|
onPress={() => context.control.close()}>
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
<Trans>Cancel</Trans>
|
<Trans>Cancel</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
|
|||||||
@@ -7,7 +7,12 @@ import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
|||||||
import {atoms as a, flatten, useTheme, web} from '#/alf'
|
import {atoms as a, flatten, useTheme, web} from '#/alf'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
import {Context, ItemContext} from '#/components/Menu/context'
|
import {
|
||||||
|
Context,
|
||||||
|
ItemContext,
|
||||||
|
useMenuContext,
|
||||||
|
useMenuItemContext,
|
||||||
|
} from '#/components/Menu/context'
|
||||||
import {
|
import {
|
||||||
ContextType,
|
ContextType,
|
||||||
GroupProps,
|
GroupProps,
|
||||||
@@ -40,10 +45,6 @@ export function useMenuControl(): Dialog.DialogControlProps {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMemoControlContext() {
|
|
||||||
return React.useContext(Context)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Root({
|
export function Root({
|
||||||
children,
|
children,
|
||||||
control,
|
control,
|
||||||
@@ -110,7 +111,7 @@ const RadixTriggerPassThrough = React.forwardRef(
|
|||||||
RadixTriggerPassThrough.displayName = 'RadixTriggerPassThrough'
|
RadixTriggerPassThrough.displayName = 'RadixTriggerPassThrough'
|
||||||
|
|
||||||
export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
||||||
const {control} = React.useContext(Context)
|
const {control} = useMenuContext()
|
||||||
const {
|
const {
|
||||||
state: hovered,
|
state: hovered,
|
||||||
onIn: onMouseEnter,
|
onIn: onMouseEnter,
|
||||||
@@ -203,7 +204,7 @@ export function Outer({
|
|||||||
|
|
||||||
export function Item({children, label, onPress, ...rest}: ItemProps) {
|
export function Item({children, label, onPress, ...rest}: ItemProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {control} = React.useContext(Context)
|
const {control} = useMenuContext()
|
||||||
const {
|
const {
|
||||||
state: hovered,
|
state: hovered,
|
||||||
onIn: onMouseEnter,
|
onIn: onMouseEnter,
|
||||||
@@ -262,7 +263,7 @@ export function Item({children, label, onPress, ...rest}: ItemProps) {
|
|||||||
|
|
||||||
export function ItemText({children, style}: ItemTextProps) {
|
export function ItemText({children, style}: ItemTextProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {disabled} = React.useContext(ItemContext)
|
const {disabled} = useMenuItemContext()
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
@@ -279,7 +280,7 @@ export function ItemText({children, style}: ItemTextProps) {
|
|||||||
|
|
||||||
export function ItemIcon({icon: Comp, position = 'left'}: ItemIconProps) {
|
export function ItemIcon({icon: Comp, position = 'left'}: ItemIconProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {disabled} = React.useContext(ItemContext)
|
const {disabled} = useMenuItemContext()
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
|
|||||||
Reference in New Issue
Block a user