Skip to content

Commit 65975dd

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Change type of SwipeRefreshLayoutManager.size prop from Int to String
Summary: This diff changes the type of the SwipeRefreshLayoutManager.size prop from Int to String in Fabric. The current implementation of this prop allows JS developers to use "int" type when fabric is enables and "int or string" types when using Fabric is disabled. Since long term we want to only support "string" type for this prop, I'm changing the type of the prop to be String. After my diff Fabric will start supporting only "string" types, non fabric screens will keep supporting "int or string" values. **Will this break production?** No, because there are no usages of RefreshControl.Size prop in fbsource **What about if someone start using this prop next week?** IMO It's very unlikely because of the nature of this prop, I will be monitoring next week and if there's an usage it will be detected by flow when trying to land D25933457. Changelog: [Android][Changed] - RefreshControl.size prop changed its type to string, the valid values are: 'default' and 'large' Reviewed By: JoshuaGross Differential Revision: D25933458 fbshipit-source-id: 55067d7405b063f1e8d9bb7a5fd7731f5f168960
1 parent 69b3016 commit 65975dd

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,8 @@ type NativeProps = $ReadOnly<{|
4242
progressBackgroundColor?: ?ColorValue,
4343
/**
4444
* Size of the refresh indicator, see RefreshControl.SIZE.
45-
*
46-
* This type isn't currently accurate. It really is specific numbers
47-
* hard coded in the Android platform.
48-
*
49-
* Also, 1 isn't actually a safe default. We are able to set this here
50-
* because native code isn't currently consuming the generated artifact.
51-
* This will end up being
52-
* size?: WithDefault<'default' | 'large', 'default'>,
5345
*/
54-
size?: WithDefault<Int32, 1>,
46+
size?: WithDefault<'default' | 'large', 'default'>,
5547
/**
5648
* Progress view top offset
5749
*/

ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,21 @@ public void setProgressBackgroundColor(ReactSwipeRefreshLayout view, Integer col
8888
}
8989

9090
// TODO(T46143833): Remove this method once the 'size' prop has been migrated to String in JS.
91-
@Override
9291
public void setSize(ReactSwipeRefreshLayout view, int value) {
9392
view.setSize(value);
9493
}
9594

95+
@Override
96+
public void setSize(ReactSwipeRefreshLayout view, String size) {
97+
if (size == null || size.equals("default")) {
98+
view.setSize(SwipeRefreshLayout.DEFAULT);
99+
} else if (size.equals("large")) {
100+
view.setSize(SwipeRefreshLayout.LARGE);
101+
} else {
102+
throw new IllegalArgumentException("Size must be 'default' or 'large', received: " + size);
103+
}
104+
}
105+
96106
// This prop temporarily takes both 0 and 1 as well as 'default' and 'large'.
97107
// 0 and 1 are deprecated and will be removed in a future release.
98108
// See T46143833
@@ -103,15 +113,7 @@ public void setSize(ReactSwipeRefreshLayout view, Dynamic size) {
103113
} else if (size.getType() == ReadableType.Number) {
104114
view.setSize(size.asInt());
105115
} else if (size.getType() == ReadableType.String) {
106-
final String sizeStr = size.asString();
107-
if (sizeStr.equals("default")) {
108-
view.setSize(SwipeRefreshLayout.DEFAULT);
109-
} else if (sizeStr.equals("large")) {
110-
view.setSize(SwipeRefreshLayout.LARGE);
111-
} else {
112-
throw new IllegalArgumentException(
113-
"Size must be 'default' or 'large', received: " + sizeStr);
114-
}
116+
setSize(view, size.asString());
115117
} else {
116118
throw new IllegalArgumentException("Size must be 'default' or 'large'");
117119
}

0 commit comments

Comments
 (0)