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

[Sheets] [Pt. 12] Add event for selected snap point change #5584

Merged
merged 73 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
5a98ea6
Include ghost hook to statically export fonts (#5553)
estrattonbailey Oct 1, 2024
801cb62
close all dialogs
haileyok Oct 1, 2024
a17892d
remove a bunch of to-be-useless stuff
haileyok Oct 1, 2024
3971254
remove `Dialog.Handle` uses
haileyok Oct 1, 2024
64f849b
rm handle component
haileyok Oct 1, 2024
6dec099
type
haileyok Oct 1, 2024
d0149a9
get scrollview working
haileyok Oct 1, 2024
40030ba
tidy
haileyok Oct 1, 2024
0b55acd
bump
haileyok Oct 1, 2024
368a9df
bump gesture handler
haileyok Oct 1, 2024
a4c7e2f
tweak types
haileyok Oct 1, 2024
e1ccacc
add props back
haileyok Oct 1, 2024
b900ac6
update types
haileyok Oct 2, 2024
baf1923
update other dialog views
haileyok Oct 2, 2024
a3737f0
replace all buttons with `BottomSheetButton`
haileyok Oct 2, 2024
e2f8e7c
fix type
haileyok Oct 2, 2024
81906df
wizard remove buttons
haileyok Oct 2, 2024
cdfdf49
fix
haileyok Oct 2, 2024
8bd6b2d
fix embed consent
haileyok Oct 2, 2024
65bfd89
buttons in account switcher
haileyok Oct 2, 2024
87c83dd
custom bottom sheet link
haileyok Oct 2, 2024
5a60190
nesting support
haileyok Oct 2, 2024
f251a43
Add intent/verify-email to go server (#5554)
estrattonbailey Oct 2, 2024
3569873
Tweak verify email dialog (#5555)
estrattonbailey Oct 2, 2024
1a7885b
Add suspense boundary in onboarding (#5556)
estrattonbailey Oct 2, 2024
d4b8401
android support
haileyok Oct 2, 2024
1ca6d36
fix type
haileyok Oct 2, 2024
a444fc5
import order (#5571)
haileyok Oct 2, 2024
3972d3d
Ignore built files (#5572)
estrattonbailey Oct 2, 2024
4059668
Make reply prompt more subtle on desktop (#5569)
mozzius Oct 2, 2024
b5a5113
simplify pressable changes
haileyok Oct 2, 2024
349b8b7
rm
haileyok Oct 2, 2024
1ea82c3
rename for clairity
haileyok Oct 2, 2024
f558eb6
fix other buttons in dialogs
haileyok Oct 2, 2024
f365ae0
tweak
haileyok Oct 2, 2024
ca0888c
more fixes
haileyok Oct 2, 2024
43eb47f
Merge remote-tracking branch 'origin/main' into hailey/dialogs-pt10
haileyok Oct 2, 2024
13c9c79
move files around (#5576)
mozzius Oct 2, 2024
c2dac85
Delete messages NUX (#5574)
mozzius Oct 2, 2024
1357ac3
bump
haileyok Oct 2, 2024
3fabcc2
revert some changes
haileyok Oct 2, 2024
1ad73e1
Merge remote-tracking branch 'origin/hailey/dialogs-pt1' into hailey/…
haileyok Oct 2, 2024
b0c0aee
custom bottom sheet link
haileyok Oct 2, 2024
84d32e3
simplify pressable changes
haileyok Oct 2, 2024
5fe4ee9
rm
haileyok Oct 2, 2024
839d6dc
rename for clairity
haileyok Oct 2, 2024
1d5a3ef
tweak
haileyok Oct 2, 2024
6d7b54c
fix namE
haileyok Oct 2, 2024
10cb87b
use context to pick default pressable component
haileyok Oct 2, 2024
431f1ff
adjust
haileyok Oct 2, 2024
fee2468
Merge branch 'hailey/dialogs-pt7-rework' into hailey/dialogs-pt8
haileyok Oct 2, 2024
bb33aa0
revert all the button import changes
haileyok Oct 3, 2024
67e4d77
revert all the changes that are not needed'
haileyok Oct 3, 2024
7ef51ac
Merge branch 'hailey/dialogs-pt8' into hailey/dialogs-pt9
haileyok Oct 3, 2024
1bda59c
Merge branch 'hailey/dialogs-pt9' into hailey/dialogs-pt10
haileyok Oct 3, 2024
5c36d8c
remove unused type
haileyok Oct 3, 2024
24bebec
Merge remote-tracking branch 'origin/main' into hailey/dialogs-pt10
haileyok Oct 3, 2024
d007151
move into repo
haileyok Oct 3, 2024
2ac8308
lint
haileyok Oct 3, 2024
52532fb
add config
haileyok Oct 3, 2024
2b98055
update type imports
haileyok Oct 3, 2024
7ee865f
fix import
haileyok Oct 3, 2024
7489a70
add event to ios
haileyok Oct 3, 2024
0ce5d44
simplify logic
haileyok Oct 3, 2024
b6adc93
ensure event fires on open
haileyok Oct 3, 2024
086dde7
log
haileyok Oct 3, 2024
83d1c38
Allow default PressableComponent override
estrattonbailey Oct 3, 2024
639a7ea
fix accessibility
haileyok Oct 3, 2024
8295c23
before spread
haileyok Oct 3, 2024
b64a294
clean
haileyok Oct 3, 2024
31e6fb8
Nitpick naming, use normal Pressable on web
estrattonbailey Oct 3, 2024
3daf2f1
Merge remote-tracking branch 'origin/eric/dialogs-pt12' into hailey/d…
haileyok Oct 3, 2024
b9ad4b2
Merge remote-tracking branch 'origin/hailey/dialogs-pt1' into hailey/…
haileyok Oct 3, 2024
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
13 changes: 11 additions & 2 deletions modules/bottom-sheet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import {BottomSheetState, BottomSheetViewProps} from './src/BottomSheet.types'
import {
BottomSheetSnapPoint,
BottomSheetState,
BottomSheetViewProps,
} from './src/BottomSheet.types'
import {BottomSheetView} from './src/BottomSheetView'

export {type BottomSheetState, BottomSheetView, type BottomSheetViewProps}
export {
BottomSheetSnapPoint,
type BottomSheetState,
BottomSheetView,
type BottomSheetViewProps,
}
11 changes: 6 additions & 5 deletions modules/bottom-sheet/ios/BottomSheetModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class BottomSheetModule: Module {

View(SheetView.self) {
Events([
"onAttemptDismiss",
"onSnapPointChange",
"onStateChange",
"onAttemptDismiss"
])

AsyncFunction("dismiss") { (view: SheetView) in
Expand All @@ -26,10 +27,6 @@ public class BottomSheetModule: Module {
view.cornerRadius = CGFloat(prop)
}

Prop("preventDismiss") { (view: SheetView, prop: Bool) in
view.preventDismiss = prop
}

Prop("minHeight") { (view: SheetView, prop: Double) in
view.minHeight = prop
}
Expand All @@ -38,6 +35,10 @@ public class BottomSheetModule: Module {
view.maxHeight = prop
}

Prop("preventDismiss") { (view: SheetView, prop: Bool) in
view.preventDismiss = prop
}

Prop("preventExpansion") { (view: SheetView, prop: Bool) in
view.preventExpansion = prop
}
Expand Down
23 changes: 21 additions & 2 deletions modules/bottom-sheet/ios/SheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
private var innerView: UIView?

// Events
private let onStateChange = EventDispatcher()
private let onAttemptDismiss = EventDispatcher()
private let onSnapPointChange = EventDispatcher()
private let onStateChange = EventDispatcher()

// Open event firing
private var isOpen: Bool = false {
Expand Down Expand Up @@ -51,6 +52,19 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}
}
}
private var selectedDetentIdentifier: UISheetPresentationController.Detent.Identifier? {
didSet {
if selectedDetentIdentifier == .large {
onSnapPointChange([
"snapPoint": 2
])
} else {
onSnapPointChange([
"snapPoint": 1
])
}
}
}

// MARK: - Lifecycle

Expand Down Expand Up @@ -103,11 +117,12 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
}

let sheetVc = SheetViewController()
sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
if let sheet = sheetVc.sheetPresentationController {
sheet.delegate = self
sheet.preferredCornerRadius = self.cornerRadius
self.selectedDetentIdentifier = sheet.selectedDetentIdentifier
}
sheetVc.setDetents(contentHeight: self.clampHeight(contentHeight), preventExpansion: self.preventExpansion)
sheetVc.view.addSubview(innerView)

self.sheetVc = sheetVc
Expand Down Expand Up @@ -158,4 +173,8 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
self.destroy()
}

func sheetPresentationControllerDidChangeSelectedDetentIdentifier(_ sheetPresentationController: UISheetPresentationController) {
self.selectedDetentIdentifier = sheetPresentationController.selectedDetentIdentifier
}
}
10 changes: 10 additions & 0 deletions modules/bottom-sheet/src/BottomSheet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import {ColorValue, NativeSyntheticEvent} from 'react-native'

export type BottomSheetState = 'closed' | 'closing' | 'open' | 'opening'

export enum BottomSheetSnapPoint {
Hidden,
Partial,
Full,
}

export interface BottomSheetViewProps {
children: React.ReactNode
cornerRadius?: number
Expand All @@ -15,6 +21,10 @@ export interface BottomSheetViewProps {
minHeight?: number
maxHeight?: number

onAttemptDismiss?: (event: NativeSyntheticEvent<object>) => void
onSnapPointChange?: (
event: NativeSyntheticEvent<{snapPoint: BottomSheetSnapPoint}>,
) => void
onStateChange?: (
event: NativeSyntheticEvent<{state: BottomSheetState}>,
) => void
Expand Down
Empty file.
12 changes: 7 additions & 5 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ export const Button = React.forwardRef<View, ButtonProps>(
},
ref,
) => {
// This will pick the correct default pressable to use. If we are inside a dialog, we need to use the RNGH
// pressable so that it is usable inside the dialog.
const {insideDialog} = useDialogContext()
/*
* This will pick the correct default pressable to use. If we are inside a
* native dialog, we need to use the RNGH pressable.
*/
const {isNativeDialog} = useDialogContext()
if (!PressableComponent) {
if (insideDialog) {
if (isNativeDialog) {
PressableComponent = NormalizedRNGHPressable
} else {
PressableComponent = Pressable
Expand Down Expand Up @@ -468,7 +470,7 @@ export const Button = React.forwardRef<View, ButtonProps>(
role="button"
accessibilityHint={undefined} // optional
{...rest}
// @ts-expect-error ref type
// @ts-ignore - this will always be a pressable
ref={ref}
aria-label={label}
aria-pressed={state.pressed}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Dialog/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
DialogControlRefProps,
DialogOuterProps,
} from '#/components/Dialog/types'
import {BottomSheetSnapPoint} from '../../../modules/bottom-sheet/src/BottomSheet.types'

export const Context = React.createContext<DialogContextProps>({
close: () => {},
insideDialog: false,
isNativeDialog: false,
nativeSnapPoint: BottomSheetSnapPoint.Hidden,
})

export function useDialogContext() {
Expand Down
25 changes: 21 additions & 4 deletions src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {isIOS} from '#/platform/detection'
import {useDialogStateControlContext} from '#/state/dialogs'
import {List, ListMethods, ListProps} from '#/view/com/util/List'
import {atoms as a, flatten, useTheme} from '#/alf'
import {Context} from '#/components/Dialog/context'
import {Context, useDialogContext} from '#/components/Dialog/context'
import {
DialogControlProps,
DialogInnerProps,
DialogOuterProps,
} from '#/components/Dialog/types'
import {createInput} from '#/components/forms/TextField'
import {Portal} from '#/components/Portal'
import {BottomSheetView} from '../../../modules/bottom-sheet'
import {
BottomSheetSnapPoint,
BottomSheetView,
} from '../../../modules/bottom-sheet'

export {useDialogContext, useDialogControl} from '#/components/Dialog/context'
export * from '#/components/Dialog/types'
Expand Down Expand Up @@ -57,6 +60,10 @@ export function OuterWithoutPortal({
const closeCallbacks = React.useRef<(() => void)[]>([])
const {setDialogIsOpen} = useDialogStateControlContext()

const [snapPoint, setSnapPoint] = React.useState<BottomSheetSnapPoint>(
BottomSheetSnapPoint.Partial,
)

const callQueuedCallbacks = React.useCallback(() => {
for (const cb of closeCallbacks.current) {
try {
Expand Down Expand Up @@ -103,7 +110,10 @@ export function OuterWithoutPortal({
[open, close],
)

const context = React.useMemo(() => ({close, insideDialog: true}), [close])
const context = React.useMemo(
() => ({close, isNativeDialog: true, nativeSnapPoint: snapPoint}),
[close, snapPoint],
)

const Wrapper = isIOS ? View : GestureHandlerRootView

Expand All @@ -113,6 +123,9 @@ export function OuterWithoutPortal({
ref={ref}
topInset={30}
bottomInset={insets.bottom}
onSnapPointChange={e => {
setSnapPoint(e.nativeEvent.snapPoint)
}}
onStateChange={e => {
if (e.nativeEvent.state === 'closed') {
onCloseAnimationComplete()
Expand Down Expand Up @@ -147,8 +160,12 @@ export function Inner({children, style}: DialogInnerProps) {
export const ScrollableInner = React.forwardRef<ScrollView, DialogInnerProps>(
function ScrollableInner({children, style}, ref) {
const insets = useSafeAreaInsets()
const {nativeSnapPoint} = useDialogContext()
return (
<ScrollView style={[a.px_xl, style]} ref={ref}>
<ScrollView
style={[a.px_xl, style]}
ref={ref}
bounces={nativeSnapPoint === BottomSheetSnapPoint.Full}>
{children}
<View style={{height: insets.bottom + a.pt_5xl.paddingTop}} />
</ScrollView>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialog/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export function Outer({
const context = React.useMemo(
() => ({
close,
insideDialog: true,
isNativeDialog: false,
nativeSnapPoint: 0,
}),
[close],
)
Expand Down
4 changes: 3 additions & 1 deletion src/components/Dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {

import {ViewStyleProp} from '#/alf'
import {BottomSheetViewProps} from '../../../modules/bottom-sheet'
import {BottomSheetSnapPoint} from '../../../modules/bottom-sheet/src/BottomSheet.types'

type A11yProps = Required<AccessibilityProps>

Expand Down Expand Up @@ -37,7 +38,8 @@ export type DialogControlProps = DialogControlRefProps & {

export type DialogContextProps = {
close: DialogControlProps['close']
insideDialog: boolean
isNativeDialog: boolean
nativeSnapPoint: BottomSheetSnapPoint
}

export type DialogControlOpenOptions = {
Expand Down
2 changes: 2 additions & 0 deletions src/components/NormalizedRNGHPressable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class NormalizedRNGHPressable extends React.Component<PressableProps> {
render() {
return (
<BSPressable
accessible={true}
accessibilityRole="button"
{...this.props}
onPress={this.onPress}
onLongPress={this.onLongPress}
Expand Down
Loading