mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement ScrollView.contentInsetAdjustmentBehavior
Summary: Changelog: [internal] Fabric's ScrollView was ignoring value of `ScrollView.contentInsetAdjustmentBehavior`, this diff fixes that. Reviewed By: shergin Differential Revision: D23102235 fbshipit-source-id: 8cf42e730b560a21d56d7e007059109ccd01154e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9c6e05ad5
commit
c429ee9974
@@ -201,6 +201,21 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
|
||||
scrollView.snapToOffsets = snapToOffsets;
|
||||
}
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
if (oldScrollViewProps.contentInsetAdjustmentBehavior != newScrollViewProps.contentInsetAdjustmentBehavior) {
|
||||
auto const contentInsetAdjustmentBehavior = newScrollViewProps.contentInsetAdjustmentBehavior;
|
||||
if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::Never) {
|
||||
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
} else if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::Automatic) {
|
||||
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
|
||||
} else if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::ScrollableAxes) {
|
||||
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
|
||||
} else if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::Always) {
|
||||
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MAP_SCROLL_VIEW_PROP(disableIntervalMomentum);
|
||||
MAP_SCROLL_VIEW_PROP(snapToInterval);
|
||||
|
||||
|
||||
@@ -159,7 +159,12 @@ ScrollViewProps::ScrollViewProps(
|
||||
snapToStart(
|
||||
convertRawProp(rawProps, "snapToStart", sourceProps.snapToStart, {})),
|
||||
snapToEnd(
|
||||
convertRawProp(rawProps, "snapToEnd", sourceProps.snapToEnd, {})) {}
|
||||
convertRawProp(rawProps, "snapToEnd", sourceProps.snapToEnd, {})),
|
||||
contentInsetAdjustmentBehavior(convertRawProp(
|
||||
rawProps,
|
||||
"contentInsetAdjustmentBehavior",
|
||||
sourceProps.contentInsetAdjustmentBehavior,
|
||||
{ContentInsetAdjustmentBehavior::Never})) {}
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ class ScrollViewProps final : public ViewProps {
|
||||
std::vector<Float> snapToOffsets{};
|
||||
bool snapToStart{true};
|
||||
bool snapToEnd{true};
|
||||
ContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior{
|
||||
ContentInsetAdjustmentBehavior::Never};
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
|
||||
@@ -70,6 +70,29 @@ inline void fromRawValue(
|
||||
abort();
|
||||
}
|
||||
|
||||
inline void fromRawValue(
|
||||
const RawValue &value,
|
||||
ContentInsetAdjustmentBehavior &result) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "never") {
|
||||
result = ContentInsetAdjustmentBehavior::Never;
|
||||
return;
|
||||
}
|
||||
if (string == "automatic") {
|
||||
result = ContentInsetAdjustmentBehavior::Automatic;
|
||||
return;
|
||||
}
|
||||
if (string == "scrollableAxes") {
|
||||
result = ContentInsetAdjustmentBehavior::ScrollableAxes;
|
||||
return;
|
||||
}
|
||||
if (string == "always") {
|
||||
result = ContentInsetAdjustmentBehavior::Always;
|
||||
return;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
inline std::string toString(const ScrollViewSnapToAlignment &value) {
|
||||
switch (value) {
|
||||
case ScrollViewSnapToAlignment::Start:
|
||||
@@ -103,5 +126,18 @@ inline std::string toString(const ScrollViewKeyboardDismissMode &value) {
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string toString(const ContentInsetAdjustmentBehavior &value) {
|
||||
switch (value) {
|
||||
case ContentInsetAdjustmentBehavior::Never:
|
||||
return "never";
|
||||
case ContentInsetAdjustmentBehavior::Automatic:
|
||||
return "automatic";
|
||||
case ContentInsetAdjustmentBehavior::ScrollableAxes:
|
||||
return "scrollableAxes";
|
||||
case ContentInsetAdjustmentBehavior::Always:
|
||||
return "always";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -16,5 +16,12 @@ enum class ScrollViewIndicatorStyle { Default, Black, White };
|
||||
|
||||
enum class ScrollViewKeyboardDismissMode { None, OnDrag, Interactive };
|
||||
|
||||
enum class ContentInsetAdjustmentBehavior {
|
||||
Never,
|
||||
Automatic,
|
||||
ScrollableAxes,
|
||||
Always
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
Reference in New Issue
Block a user