mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use generated Java delegate for setting properties on ReactDrawerLayoutManager
Summary: This diff migrates `ReactDrawerLayoutManager` to use the generated `AndroidDrawerLayoutManagerDelegate` for setting its properties. Reviewed By: mdvacca Differential Revision: D17343383 fbshipit-source-id: 85cd7ee3531b152da2601048f5e458f5dad73ad6
This commit is contained in:
committed by
Facebook Github Bot
parent
92f3b4a27f
commit
81f567d4aa
+1
-1
@@ -33,7 +33,7 @@ public class AndroidDrawerLayoutManagerDelegate<T extends View, U extends BaseVi
|
||||
mViewManager.setDrawerPosition(view, (String) value);
|
||||
break;
|
||||
case "drawerWidth":
|
||||
mViewManager.setDrawerWidth(view, value == null ? 0f : ((Double) value).floatValue());
|
||||
mViewManager.setDrawerWidth(view, value == null ? null : ((Double) value).floatValue());
|
||||
break;
|
||||
case "drawerLockMode":
|
||||
mViewManager.setDrawerLockMode(view, (String) value);
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ public interface AndroidDrawerLayoutManagerInterface<T extends View> {
|
||||
void setKeyboardDismissMode(T view, @Nullable String value);
|
||||
void setDrawerBackgroundColor(T view, @Nullable Integer value);
|
||||
void setDrawerPosition(T view, @Nullable String value);
|
||||
void setDrawerWidth(T view, float value);
|
||||
void setDrawerWidth(T view, @Nullable Float value);
|
||||
void setDrawerLockMode(T view, @Nullable String value);
|
||||
void setStatusBarBackgroundColor(T view, @Nullable Integer value);
|
||||
void openDrawer(T view);
|
||||
|
||||
@@ -24,5 +24,6 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/uimanager:uimanager"),
|
||||
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
|
||||
react_native_target("java/com/facebook/react/views/scroll:scroll"),
|
||||
react_native_target("java/com/facebook/react/viewmanagers:viewmanagers"),
|
||||
],
|
||||
)
|
||||
|
||||
+69
-16
@@ -8,7 +8,6 @@ package com.facebook.react.views.drawer;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
@@ -22,8 +21,11 @@ import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewGroupManager;
|
||||
import com.facebook.react.uimanager.ViewManagerDelegate;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.viewmanagers.AndroidDrawerLayoutManagerDelegate;
|
||||
import com.facebook.react.viewmanagers.AndroidDrawerLayoutManagerInterface;
|
||||
import com.facebook.react.views.drawer.events.DrawerClosedEvent;
|
||||
import com.facebook.react.views.drawer.events.DrawerOpenedEvent;
|
||||
import com.facebook.react.views.drawer.events.DrawerSlideEvent;
|
||||
@@ -32,13 +34,20 @@ import java.util.Map;
|
||||
|
||||
/** View Manager for {@link ReactDrawerLayout} components. */
|
||||
@ReactModule(name = ReactDrawerLayoutManager.REACT_CLASS)
|
||||
public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout> {
|
||||
public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout>
|
||||
implements AndroidDrawerLayoutManagerInterface<ReactDrawerLayout> {
|
||||
|
||||
public static final String REACT_CLASS = "AndroidDrawerLayout";
|
||||
|
||||
public static final int OPEN_DRAWER = 1;
|
||||
public static final int CLOSE_DRAWER = 2;
|
||||
|
||||
private final ViewManagerDelegate<ReactDrawerLayout> mDelegate;
|
||||
|
||||
public ReactDrawerLayoutManager() {
|
||||
mDelegate = new AndroidDrawerLayoutManagerDelegate<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getName() {
|
||||
return REACT_CLASS;
|
||||
@@ -47,9 +56,8 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
@Override
|
||||
protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) {
|
||||
view.addDrawerListener(
|
||||
new DrawerEventEmitter(
|
||||
view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher())
|
||||
);
|
||||
new DrawerEventEmitter(
|
||||
view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +65,15 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
return new ReactDrawerLayout(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawerPosition(ReactDrawerLayout view, @Nullable String value) {
|
||||
if (value == null) {
|
||||
view.setDrawerPosition(Gravity.START);
|
||||
} else {
|
||||
setDrawerPositionInternal(view, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "drawerPosition")
|
||||
public void setDrawerPosition(ReactDrawerLayout view, Dynamic drawerPosition) {
|
||||
if (drawerPosition.isNull()) {
|
||||
@@ -71,23 +88,25 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
"Unknown drawerPosition " + drawerPositionNum);
|
||||
}
|
||||
} else if (drawerPosition.getType() == ReadableType.String) {
|
||||
final String drawerPositionStr = drawerPosition.asString();
|
||||
|
||||
if (drawerPositionStr.equals("left")) {
|
||||
view.setDrawerPosition(Gravity.START);
|
||||
} else if (drawerPositionStr.equals("right")) {
|
||||
view.setDrawerPosition(Gravity.END);
|
||||
} else {
|
||||
throw new JSApplicationIllegalArgumentException(
|
||||
"drawerPosition must be 'left' or 'right', received" + drawerPositionStr);
|
||||
}
|
||||
setDrawerPositionInternal(view, drawerPosition.asString());
|
||||
} else {
|
||||
throw new JSApplicationIllegalArgumentException("drawerPosition must be a string or int");
|
||||
}
|
||||
}
|
||||
|
||||
private void setDrawerPositionInternal(ReactDrawerLayout view, String drawerPosition) {
|
||||
if (drawerPosition.equals("left")) {
|
||||
view.setDrawerPosition(Gravity.START);
|
||||
} else if (drawerPosition.equals("right")) {
|
||||
view.setDrawerPosition(Gravity.END);
|
||||
} else {
|
||||
throw new JSApplicationIllegalArgumentException(
|
||||
"drawerPosition must be 'left' or 'right', received" + drawerPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "drawerWidth", defaultFloat = Float.NaN)
|
||||
public void getDrawerWidth(ReactDrawerLayout view, float width) {
|
||||
public void setDrawerWidth(ReactDrawerLayout view, float width) {
|
||||
int widthInPx =
|
||||
Float.isNaN(width)
|
||||
? ReactDrawerLayout.DEFAULT_DRAWER_WIDTH
|
||||
@@ -95,6 +114,16 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
view.setDrawerWidth(widthInPx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawerWidth(ReactDrawerLayout view, @Nullable Float width) {
|
||||
int widthInPx =
|
||||
width == null
|
||||
? ReactDrawerLayout.DEFAULT_DRAWER_WIDTH
|
||||
: Math.round(PixelUtil.toPixelFromDIP(width));
|
||||
view.setDrawerWidth(widthInPx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "drawerLockMode")
|
||||
public void setDrawerLockMode(ReactDrawerLayout view, @Nullable String drawerLockMode) {
|
||||
if (drawerLockMode == null || "unlocked".equals(drawerLockMode)) {
|
||||
@@ -108,6 +137,25 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openDrawer(ReactDrawerLayout view) {
|
||||
view.openDrawer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeDrawer(ReactDrawerLayout view) {
|
||||
view.closeDrawer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeyboardDismissMode(ReactDrawerLayout view, @Nullable String value) {}
|
||||
|
||||
@Override
|
||||
public void setDrawerBackgroundColor(ReactDrawerLayout view, @Nullable Integer value) {}
|
||||
|
||||
@Override
|
||||
public void setStatusBarBackgroundColor(ReactDrawerLayout view, @Nullable Integer value) {}
|
||||
|
||||
@Override
|
||||
public void setElevation(@NonNull ReactDrawerLayout view, float elevation) {
|
||||
view.setDrawerElevation(PixelUtil.toPixelFromDIP(elevation));
|
||||
@@ -183,6 +231,11 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
parent.setDrawerProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewManagerDelegate<ReactDrawerLayout> getDelegate() {
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
public static class DrawerEventEmitter implements DrawerLayout.DrawerListener {
|
||||
|
||||
private final DrawerLayout mDrawerLayout;
|
||||
|
||||
Reference in New Issue
Block a user