DrawerLayoutAndroid now takes strings for drawerPosition

Summary:
Previously DrawerLayoutAndroid required taking an int as the drawerPosition. This required a complex dance of pulling these constant values off of the native view config. As we are going to stop sending view configs from native and instead hardcode them in JS we can't do that anymore.

In this commit we are supporting the old style as well as the new style. The old way of specifying the sizes will go away in a future release.

Changelog:
[Android][Added] - DrawerLayoutAndroid now supports strings and not just numbers for drawerPosition.

Reviewed By: mdvacca

Differential Revision: D15912607

fbshipit-source-id: b444454a1e74f8f659995b9ebe5e164ac9660138
This commit is contained in:
Eli White 2019-06-21 15:55:46 -07:00 коммит произвёл Facebook Github Bot
Родитель 01a42bc368
Коммит 1d0b397485
1 изменённых файлов: 25 добавлений и 5 удалений

Просмотреть файл

@ -12,8 +12,10 @@ import androidx.drawerlayout.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
@ -60,12 +62,30 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
return new ReactDrawerLayout(context);
}
@ReactProp(name = "drawerPosition", defaultInt = Gravity.START)
public void setDrawerPosition(ReactDrawerLayout view, int drawerPosition) {
if (Gravity.START == drawerPosition || Gravity.END == drawerPosition) {
view.setDrawerPosition(drawerPosition);
@ReactProp(name = "drawerPosition")
public void setDrawerPosition(ReactDrawerLayout view, Dynamic drawerPosition) {
if (drawerPosition.isNull()) {
view.setDrawerPosition(Gravity.START);
} else if (drawerPosition.getType() == ReadableType.Number) {
final int drawerPositionNum = drawerPosition.asInt();
if (Gravity.START == drawerPositionNum || Gravity.END == drawerPositionNum) {
view.setDrawerPosition(drawerPositionNum);
} else {
throw new JSApplicationIllegalArgumentException("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);
}
} else {
throw new JSApplicationIllegalArgumentException("Unknown drawerPosition " + drawerPosition);
throw new JSApplicationIllegalArgumentException("drawerPosition must be a string or int");
}
}