Ответ 1
После большой отладки, наконец, я получил ее, мне пришлось сделать 2 вещи, прежде всего, чтобы переопределить функцию onMeasure и применить высоту ребенка в setMeasuredDimension
и, по-видимому, устранить проблему с высотой, но после небольшой игры бит, любое изменение состояния разбивает положение нижнего листа, поэтому мне пришлось вызвать requestLayout для каждого изменения состояния через UIManager.dispatchViewManagerCommand и работает очень хорошо.
Итак, это исправление, которое исправляет.
BottomSheetBehaviorView.js
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
View child = this.getChildAt(0);
if (child != null) {
setMeasuredDimension(widthMeasureSpec, child.getHeight());
}
}
BottomSheetBehaviorManager.js
@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("setRequestLayout", COMMAND_SET_REQUEST_LAYOUT);
}
@Override
public void receiveCommand(BottomSheetBehaviorView view, int commandType, @Nullable ReadableArray args) {
if (commandType == COMMAND_SET_REQUEST_LAYOUT) {
setRequestLayout(view);
}
}
private void setRequestLayout(BottomSheetBehaviorView view) {
view.requestLayout();
}
BottomSheetBehavior.js
componentDidUpdate() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.RCTBottomSheetBehaviorAndroid.Commands.setRequestLayout,
[],
)
}
Update
Я понял, что состояние обновления во время скольжения мерцает во всех макетах, после поиска кода некоторых библиотек я нашел функцию needsCustomLayoutForChildren, которая описана в ViewGroupManager.java
/**
* Returns whether this View type needs to handle laying out its own children instead of
* deferring to the standard css-layout algorithm.
* Returns true for the layout to *not* be automatically invoked. Instead onLayout will be
* invoked as normal and it is the View instance responsibility to properly call layout on its
* children.
* Returns false for the default behavior of automatically laying out children without going
* through the ViewGroup onLayout method. In that case, onLayout for this View type must *not*
* call layout on its children.
*/
public boolean needsCustomLayoutForChildren() {
return false;
}
Итак, я исправлено, возвращая true в CoordinatorLayoutManager.java
Вот как это выглядит.