Navigation stack native primitives (#139)

Adds support for stack navigation primitives (UINavigationViewController and Android fragment container with back button support)
This commit is contained in:
Krzysztof Magiera
2019-09-05 13:55:14 +02:00
committed by GitHub
parent 4c2aded426
commit 80a466970e
48 changed files with 4303 additions and 985 deletions

View File

@@ -0,0 +1,77 @@
package com.swmansion.rnscreens;
import android.view.View;
import android.view.ViewParent;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.views.view.ReactViewGroup;
public class ScreenStackHeaderSubview extends ReactViewGroup {
public class Measurements {
public int width;
public int height;
}
public enum Type {
LEFT,
CENTER,
TITLE,
RIGHT
}
private int mReactWidth, mReactHeight;
private final UIManagerModule mUIManager;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY &&
MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY) {
// dimensions provided by react
mReactWidth = MeasureSpec.getSize(widthMeasureSpec);
mReactHeight = MeasureSpec.getSize(heightMeasureSpec);
ViewParent parent = getParent();
if (parent != null) {
forceLayout();
((View) parent).requestLayout();
}
}
setMeasuredDimension(mReactWidth, mReactHeight);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (changed && (mType == Type.CENTER || mType == Type.TITLE)) {
Measurements measurements = new Measurements();
measurements.width = right - left;
if (mType == Type.CENTER) {
// if we want the view to be centered we need to account for the fact that right and left
// paddings may not be equal.
View parent = (View) getParent();
int parentWidth = parent.getWidth();
int rightPadding = parentWidth - right;
int leftPadding = left;
measurements.width = Math.max(0, parentWidth - 2 * Math.max(rightPadding, leftPadding));
}
measurements.height = bottom - top;
mUIManager.setViewLocalData(getId(), measurements);
}
super.onLayout(changed, left, top, right, bottom);
}
private Type mType = Type.RIGHT;
public ScreenStackHeaderSubview(ReactContext context) {
super(context);
mUIManager = context.getNativeModule(UIManagerModule.class);
}
public void setType(Type type) {
mType = type;
}
public Type getType() {
return mType;
}
}