Android SwipeRefreshLayout now supports strings for size

Summary:
Previously SwipeRefreshLayout (RefreshControl on Android) required taking an int as the size. 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.

We will change the type of size from:
```
size?: ?(
  | typeof RefreshLayoutConsts.SIZE.DEFAULT
  | typeof RefreshLayoutConsts.SIZE.LARGE
),
```

to:
```
size?: ?('default' | 'large')
```

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] - RefreshControl now supports strings and not just numbers for size.

Reviewed By: mdvacca

Differential Revision: D15909582

fbshipit-source-id: 1849edc980e1698de147e88d710e0f28d0fdc8d8
This commit is contained in:
Eli White 2019-06-20 10:54:30 -07:00 коммит произвёл Facebook Github Bot
Родитель cbf1b39c66
Коммит 09fe15910e
1 изменённых файлов: 23 добавлений и 3 удалений

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

@ -12,7 +12,9 @@ import static com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager.RE
import android.graphics.Color;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ThemedReactContext;
@ -66,9 +68,27 @@ public class SwipeRefreshLayoutManager extends ViewGroupManager<ReactSwipeRefres
view.setProgressBackgroundColorSchemeColor(color);
}
@ReactProp(name = "size", defaultInt = SwipeRefreshLayout.DEFAULT)
public void setSize(ReactSwipeRefreshLayout view, int size) {
view.setSize(size);
// This prop temporarily takes both 0 and 1 as well as 'default' and 'large'.
// 0 and 1 are deprecated and will be removed in a future release.
// See T46143833
@ReactProp(name = "size")
public void setSize(ReactSwipeRefreshLayout view, Dynamic size) {
if (size.isNull()) {
view.setSize(SwipeRefreshLayout.DEFAULT);
} else if (size.getType() == ReadableType.Number) {
view.setSize(size.asInt());
} else if (size.getType() == ReadableType.String) {
final String sizeStr = size.asString();
if (sizeStr.equals("default")) {
view.setSize(SwipeRefreshLayout.DEFAULT);
} else if (sizeStr.equals("large")) {
view.setSize(SwipeRefreshLayout.LARGE);
} else {
throw new IllegalArgumentException("Size must be 'default' or 'large', received: " + sizeStr);
}
} else {
throw new IllegalArgumentException("Size must be 'default' or 'large'");
}
}
@ReactProp(name = "refreshing")