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

Supported Bottom Sheet Component (iOS) #744

Merged
merged 63 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8911fa3
Added bottom sheet view and manager ios files
grahammendick Nov 4, 2023
de06b63
Removed unsupported view manager config on ios
grahammendick Nov 4, 2023
55409d4
Logged out the height of the sheet as it animates
grahammendick Nov 4, 2023
dad5e0e
Used UIViewController directly for simplicity
grahammendick Nov 4, 2023
25ba84e
Resized content based on sheet position
grahammendick Nov 5, 2023
594aad2
Compared old and new size
grahammendick Nov 5, 2023
4d14e66
Resized when bounds did change too
grahammendick Nov 5, 2023
b537edb
Ensured only one resize runs
grahammendick Nov 5, 2023
398b059
Prevented bounds change resize if dropping
grahammendick Nov 6, 2023
26b5407
Implemented detent and change props on native
grahammendick Nov 6, 2023
6b85589
Ignored detent prop if js is lagging behind
grahammendick Nov 6, 2023
fac004a
Used peekHeight as custom collapsed detent
grahammendick Nov 6, 2023
70b5744
Removed duplicated line
grahammendick Nov 6, 2023
6e6aecf
Shared collapsed identifier
grahammendick Nov 6, 2023
dd6c728
Animated change in peekHeight
grahammendick Nov 6, 2023
a1eec96
Used optional chaining for simplicity
grahammendick Nov 6, 2023
1d73746
Implemented expanded height and offset props
grahammendick Nov 6, 2023
a9c3504
Cleared height and top on ios for simplicity
grahammendick Nov 6, 2023
8b973c8
Returned null if bottom sheet not supported
grahammendick Nov 6, 2023
b585507
Implemented halfExpandedRatio prop
grahammendick Nov 7, 2023
6b79c4f
Compared identifiers because detents not equal
grahammendick Nov 7, 2023
b7ced04
Compared with isEqual for safety
grahammendick Nov 7, 2023
7568ae9
Implemented hideable prop
grahammendick Nov 7, 2023
a442119
Implemented hidden 'detent'
grahammendick Nov 7, 2023
ac4bf5e
Fired event when detent changed to hidden
grahammendick Nov 7, 2023
42a012d
Implemented draggable prop
grahammendick Nov 7, 2023
7edabc7
Swapped around for clarity
grahammendick Nov 7, 2023
4e40747
Invalidated and closed when removed
grahammendick Nov 7, 2023
71640a7
Tweaked format
grahammendick Nov 7, 2023
cd117b8
Removed dismissing - not sure it's needed
grahammendick Nov 7, 2023
e236bc5
Allowed bottom sheet to be reopened
grahammendick Nov 8, 2023
de2142e
Implemented skipCollapsed prop
grahammendick Nov 8, 2023
e3aff74
Ensured bottom sheet view garbage collected
grahammendick Nov 8, 2023
2f8983e
Ensured bottom sheet supports reload
grahammendick Nov 8, 2023
2cb269f
Implemented largestUndimmedDetent prop
grahammendick Nov 8, 2023
d314950
Renamed for clarity
grahammendick Nov 8, 2023
6e46418
Excluded hidden and expanded from largest undimmed
grahammendick Nov 8, 2023
2e0c89c
Typed the largestUndimmedDetent prop
grahammendick Nov 8, 2023
8972fed
Matched existing code to reduce PR diff
grahammendick Nov 8, 2023
68d7eae
Removed prop else sheet stays across navigation
grahammendick Nov 8, 2023
9ff5cb3
Got app running on fabric
grahammendick Nov 9, 2023
7f99528
Started copying bottom sheet from old arch to new
grahammendick Nov 9, 2023
d45f37d
Added sheet controller so can share on old and new
grahammendick Nov 9, 2023
c8b48cb
Imported sheet controller on old and new arch
grahammendick Nov 9, 2023
4c4cf18
Copied over more bottom sheet code to new arch
grahammendick Nov 9, 2023
fbf9c70
Resized self because that's only option on fabric
grahammendick Nov 9, 2023
d931631
Removed redundant view
grahammendick Nov 9, 2023
6d8388b
Removed redundant container
grahammendick Nov 9, 2023
089a5df
Presented the sheet
grahammendick Nov 9, 2023
88880f2
Resized view when bounds change on fabric
grahammendick Nov 9, 2023
a30e585
Resized view on dropping sheet
grahammendick Nov 9, 2023
6243c10
Recycled view so can be reused
grahammendick Nov 9, 2023
78b543f
Stopped running display link when recycled
grahammendick Nov 9, 2023
d627aee
Checked for consistency with bounds listener
grahammendick Nov 9, 2023
74f3e00
Raised onDetentChanged event on new arch
grahammendick Nov 10, 2023
e68ee29
Removed blank line
grahammendick Nov 10, 2023
edae9cb
Ensured bottom sheet works with reload (tap r)
grahammendick Nov 10, 2023
f38840a
Removed pointless dismiss animation when recycling
grahammendick Nov 10, 2023
527ab18
Ensured can touch views in the bottom sheet
grahammendick Nov 10, 2023
af95f04
Converted detent to int
grahammendick Nov 10, 2023
595a1ee
Converted detent to int
grahammendick Nov 10, 2023
c96c899
Ensured scene behind is touchable when hidden
grahammendick Nov 10, 2023
c9ac65c
Hid using display for ios fabric
grahammendick Nov 10, 2023
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
15 changes: 9 additions & 6 deletions NavigationReactNative/src/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BottomSheet extends React.Component<any, any> {
}
onDetentChanged({nativeEvent}) {
var {eventCount: mostRecentEventCount, detent: nativeDetent} = nativeEvent;
var detents = (UIManager as any).getViewManagerConfig('NVBottomSheet').Constants.Detent
var detent = Object.keys(detents).find(name => detents[name] === nativeDetent)
var detents = (UIManager as any).getViewManagerConfig('NVBottomSheet').Constants?.Detent;
var detent = Platform.OS === 'android'? Object.keys(detents).find(name => detents[name] === nativeDetent) : nativeDetent;
this.dragging = !detent
if (detent) {
this.changeDetent(detent);
Expand All @@ -39,14 +39,15 @@ class BottomSheet extends React.Component<any, any> {
}
}
render() {
if (Platform.OS === 'ios') return null;
if (Platform.OS === 'ios' && +Platform.Version < 15) return null;
var { expandedHeight, expandedOffset, peekHeight, halfExpandedRatio, hideable, skipCollapsed, draggable, children } = this.props
const detents = (UIManager as any).getViewManagerConfig('NVBottomSheet').Constants.Detent
const detents = (UIManager as any).getViewManagerConfig('NVBottomSheet').Constants?.Detent;
return (
<NVBottomSheet
ref={this.ref}
detent={detents[this.state.selectedDetent]}
detent={Platform.OS === 'android' ? '' + detents[this.state.selectedDetent] : this.state.selectedDetent}
peekHeight={peekHeight}
expandedHeight={expandedHeight}
expandedOffset={expandedOffset}
fitToContents={expandedOffset == null}
halfExpandedRatio={halfExpandedRatio}
Expand All @@ -61,7 +62,9 @@ class BottomSheet extends React.Component<any, any> {
styles.bottomSheet,
expandedHeight != null ? { height: expandedHeight } : null,
expandedOffset != null ? { top: expandedOffset } : null,
expandedHeight == null && expandedOffset == null ? { top: 0 } : null
expandedHeight == null && expandedOffset == null ? { top: 0 } : null,
Platform.OS === 'ios' ? { height: undefined, top: undefined } : null,
{ display: this.state.selectedDetent !== 'hidden' ? 'flex' : 'none' },
]}
>
{children}
Expand Down
6 changes: 4 additions & 2 deletions NavigationReactNative/src/BottomSheetNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati

type NativeProps = $ReadOnly<{|
...ViewProps,
detent: Int32,
detent: string,
mostRecentEventCount: Int32,
peekHeight: Int32,
expandedHeight: Int32,
expandedOffset: Int32,
fitToContents: boolean,
halfExpandedRatio?: WithDefault<Float, -1>,
Expand All @@ -17,11 +18,12 @@ type NativeProps = $ReadOnly<{|
draggable: boolean,
sheetHeight: Double,
onDetentChanged: DirectEventHandler<$ReadOnly<{|
detent: Int32,
detent: string,
eventCount: Int32,
|}>>,
|}>;

export default (codegenNativeComponent<NativeProps>(
'NVBottomSheet',
{interfaceOnly: true}
): HostComponent<NativeProps>);
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected BottomSheetView createViewInstance(@NonNull ThemedReactContext reactCo
}

@ReactProp(name = "detent")
public void setDetent(BottomSheetView view, int detent) {
view.pendingDetent = detent;
public void setDetent(BottomSheetView view, String detent) {
view.pendingDetent = Integer.parseInt(detent);
}

@ReactProp(name = "mostRecentEventCount")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected BottomSheetView createViewInstance(@NonNull ThemedReactContext reactCo
}

@ReactProp(name = "detent")
public void setDetent(BottomSheetView view, int detent) {
view.pendingDetent = detent;
public void setDetent(BottomSheetView view, String detent) {
view.pendingDetent = Integer.parseInt(detent);
}

@ReactProp(name = "mostRecentEventCount")
Expand All @@ -57,6 +57,10 @@ public void setPeekHeight(BottomSheetView view, int peekHeight) {
view.bottomSheetBehavior.setPeekHeight((int) PixelUtil.toPixelFromDIP(peekHeight), true);
}

@Override
public void setExpandedHeight(BottomSheetView view, int value) {
}

@ReactProp(name = "expandedOffset")
public void setExpandedOffset(BottomSheetView view, int expandedOffset) {
view.bottomSheetBehavior.setExpandedOffset((int) PixelUtil.toPixelFromDIP(expandedOffset));
Expand Down
1 change: 1 addition & 0 deletions NavigationReactNative/src/cpp/navigationreactnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <jsi/jsi.h>
#include <react/renderer/components/navigationreactnative/NVActionBarComponentDescriptor.h>
#include <react/renderer/components/navigationreactnative/NVBarButtonComponentDescriptor.h>
#include <react/renderer/components/navigationreactnative/NVBottomSheetComponentDescriptor.h>
#include <react/renderer/components/navigationreactnative/NVNavigationBarComponentDescriptor.h>
#include <react/renderer/components/navigationreactnative/NVSearchBarComponentDescriptor.h>
#include <react/renderer/components/navigationreactnative/NVTabBarItemComponentDescriptor.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <react/debug/react_native_assert.h>
#include "NVBottomSheetShadowNode.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook {
namespace react {

class NVBottomSheetComponentDescriptor final
: public ConcreteComponentDescriptor<NVBottomSheetShadowNode> {
public:
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;

void adopt(ShadowNode::Unshared const &shadowNode) const override {
react_native_assert(
std::dynamic_pointer_cast<NVBottomSheetShadowNode>(shadowNode));
auto screenShadowNode =
std::static_pointer_cast<NVBottomSheetShadowNode>(shadowNode);

react_native_assert(
std::dynamic_pointer_cast<YogaLayoutableShadowNode>(screenShadowNode));
auto layoutableShadowNode =
std::static_pointer_cast<YogaLayoutableShadowNode>(screenShadowNode);

auto state =
std::static_pointer_cast<const NVBottomSheetShadowNode::ConcreteState>(
shadowNode->getState());
auto stateData = state->getData();

if (stateData.frameSize.width != 0 && stateData.frameSize.height != 0) {
layoutableShadowNode->setSize(
Size{stateData.frameSize.width, stateData.frameSize.height});
}

ConcreteComponentDescriptor::adopt(shadowNode);
}
};

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "NVBottomSheetShadowNode.h"

namespace facebook {
namespace react {

extern const char NVBottomSheetComponentName[] = "NVBottomSheet";

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "NVBottomSheetState.h"
#include <react/renderer/components/navigationreactnative/EventEmitters.h>
#include <react/renderer/components/navigationreactnative/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>

namespace facebook {
namespace react {

JSI_EXPORT extern const char NVBottomSheetComponentName[];

class JSI_EXPORT NVBottomSheetShadowNode final : public ConcreteViewShadowNode<
NVBottomSheetComponentName,
NVBottomSheetProps,
NVBottomSheetEventEmitter,
NVBottomSheetState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::RootNodeKind);
return traits;
}
};

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "NVBottomSheetState.h"

namespace facebook {
namespace react {

#ifdef ANDROID
folly::dynamic NVBottomSheetState::getDynamic() const {
return folly::dynamic::object("frameWidth", frameSize.width)(
"frameHeight", frameSize.height);
}
#endif

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <react/renderer/graphics/Float.h>
#include <react/renderer/core/graphicsConversions.h>

#ifdef ANDROID
#include <folly/dynamic.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
#endif

namespace facebook {
namespace react {

class JSI_EXPORT NVBottomSheetState final {
public:
using Shared = std::shared_ptr<const NVBottomSheetState>;

NVBottomSheetState(){};
NVBottomSheetState(Size frameSize_) : frameSize(frameSize_){};

#ifdef ANDROID
NVBottomSheetState(
NVBottomSheetState const &previousState,
folly::dynamic data)
: frameSize(Size{
(Float)data["frameWidth"].getDouble(),
(Float)data["frameHeight"].getDouble()}){};
#endif

const Size frameSize{};

#ifdef ANDROID
folly::dynamic getDynamic() const;
MapBuffer getMapBuffer() const {
return MapBufferBuilder::EMPTY();
};

#endif

#pragma mark - Getters
};

} // namespace react
} // namespace facebook
3 changes: 2 additions & 1 deletion NavigationReactNative/src/ios/NVBottomSheetComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

NS_ASSUME_NONNULL_BEGIN

@interface NVBottomSheetComponentView : RCTViewComponentView
API_AVAILABLE(ios(15.0))
@interface NVBottomSheetComponentView : RCTViewComponentView <UISheetPresentationControllerDelegate, UIAdaptivePresentationControllerDelegate>

@end

Expand Down
Loading