Skip to content

Commit

Permalink
fix(ios): fix jumping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lodev09 committed Apr 4, 2024
1 parent b9e00f2 commit 2b6e77d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
9 changes: 5 additions & 4 deletions ios/TrueSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
self.bridge = bridge

viewController = TrueSheetViewController()
viewController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]

touchHandler = RCTTouchHandler(bridge: bridge)

super.init(frame: .zero)
Expand All @@ -77,11 +79,10 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
return
}

// viewController.view.insertSubview(subview, at: 0)
viewController.view.addSubview(subview)

containerView = subview
touchHandler.attach(to: subview)
touchHandler.attach(to: containerView)
}

override func removeReactSubview(_ subview: UIView!) {
Expand Down Expand Up @@ -165,11 +166,11 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
@objc
func setBlurStyle(_ style: NSString?) {
guard let style else {
viewController.blurView.effect = nil
viewController.setBlurStyle(nil)
return
}

viewController.blurView.effect = UIBlurEffect(with: style as String)
viewController.setBlurStyle(style as String)
}

@objc
Expand Down
25 changes: 15 additions & 10 deletions ios/TrueSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe

weak var delegate: TrueSheetViewControllerDelegate?

var blurView: UIVisualEffectView
var lastViewWidth: CGFloat = 0
var detentValues: [String: SizeInfo] = [:]

var sizes: [Any] = ["medium", "large"]
var maxHeight: CGFloat?

Expand All @@ -48,10 +52,6 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
}
}

var blurView: UIVisualEffectView
var lastViewWidth: CGFloat = 0
var detentValues: [String: SizeInfo] = [:]

@available(iOS 15.0, *)
var sheet: UISheetPresentationController? {
return sheetPresentationController
Expand All @@ -73,13 +73,9 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe

super.init(nibName: nil, bundle: nil)

view.addSubview(blurView)
view.autoresizingMask = [.flexibleHeight, .flexibleWidth]

let blurEffect = UIBlurEffect(style: .light)
blurView.effect = blurEffect
blurView.frame = view.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurView.frame = view.bounds
view.insertSubview(blurView, at: 0)
}

@available(*, unavailable)
Expand Down Expand Up @@ -116,6 +112,15 @@ class TrueSheetViewController: UIViewController, UISheetPresentationControllerDe
}
}

func setBlurStyle(_ style: String?) {
guard let style else {
blurView.effect = nil
return
}

blurView.effect = UIBlurEffect(with: style)
}

/// Prepares the view controller for sheet presentation
/// Do nothing on IOS 14 and below... sad
@available(iOS 15.0, *)
Expand Down
28 changes: 11 additions & 17 deletions src/TrueSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,17 @@ export class TrueSheet extends PureComponent<TrueSheetProps, TrueSheetState> {
>
<View
collapsable={false}
style={[
$sheetWrapper,
{
borderTopLeftRadius: cornerRadius,
borderTopRightRadius: cornerRadius,

// Remove backgroundColor if `blurStyle` is set on iOS
backgroundColor: Platform.select({
ios: blurStyle ? undefined : backgroundColor ?? 'white',
android: backgroundColor ?? 'white',
}),
},
]}
style={{
overflow: Platform.select({ ios: undefined, android: 'hidden' }),
borderTopLeftRadius: cornerRadius,
borderTopRightRadius: cornerRadius,

// Remove backgroundColor if `blurStyle` is set on iOS
backgroundColor: Platform.select({
ios: blurStyle ? undefined : backgroundColor ?? 'white',
android: backgroundColor ?? 'white',
}),
}}
{...rest}
>
<View collapsable={false} style={style}>
Expand All @@ -179,7 +177,3 @@ const $nativeSheet: ViewStyle = {
width: 0,
zIndex: -9999,
}

const $sheetWrapper: ViewStyle = {
overflow: 'hidden',
}

0 comments on commit 2b6e77d

Please sign in to comment.