Skip to content

Commit ef3b16e

Browse files
makovkastarfacebook-github-bot
authored andcommitted
Use generated Java delegate for setting properties on SwipeRefreshLayoutManager
Summary: This diff migrates `SwipeRefreshLayoutManager` to use the generated `AndroidSwipeRefreshLayoutManagerDelegate`. Reviewed By: JoshuaGross, mdvacca Differential Revision: D17225894 fbshipit-source-id: e659d2a9cb5dba42c589559f61a0e98330e21612
1 parent 1eb8ef5 commit ef3b16e

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type NativeProps = $ReadOnly<{|
2828
/**
2929
* Whether the pull to refresh functionality is enabled.
3030
*/
31-
enabled?: WithDefault<boolean, false>,
31+
enabled?: WithDefault<boolean, true>,
3232
/**
3333
* The colors (at least one) that will be used to draw the refresh indicator.
3434
*/

ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwipeRefreshLayoutManagerDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AndroidSwipeRefreshLayoutManagerDelegate(U viewManager) {
2424
public void setProperty(T view, String propName, @Nullable Object value) {
2525
switch (propName) {
2626
case "enabled":
27-
mViewManager.setEnabled(view, value == null ? false : (boolean) value);
27+
mViewManager.setEnabled(view, value == null ? true : (boolean) value);
2828
break;
2929
case "colors":
3030
mViewManager.setColors(view, (ReadableArray) value);

ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ rn_android_library(
2323
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
2424
react_native_target("java/com/facebook/react/views/scroll:scroll"),
2525
],
26+
exported_deps = [
27+
react_native_target("java/com/facebook/react/viewmanagers:viewmanagers"),
28+
],
2629
)

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,29 @@
2020
import com.facebook.react.uimanager.ThemedReactContext;
2121
import com.facebook.react.uimanager.UIManagerModule;
2222
import com.facebook.react.uimanager.ViewGroupManager;
23+
import com.facebook.react.uimanager.ViewManagerDelegate;
2324
import com.facebook.react.uimanager.ViewProps;
2425
import com.facebook.react.uimanager.annotations.ReactProp;
26+
import com.facebook.react.viewmanagers.AndroidSwipeRefreshLayoutManagerDelegate;
27+
import com.facebook.react.viewmanagers.AndroidSwipeRefreshLayoutManagerInterface;
2528
import java.util.Map;
2629

2730
/**
2831
* ViewManager for {@link ReactSwipeRefreshLayout} which allows the user to "pull to refresh" a
2932
* child view. Emits an {@code onRefresh} event when this happens.
3033
*/
3134
@ReactModule(name = REACT_CLASS)
32-
public class SwipeRefreshLayoutManager extends ViewGroupManager<ReactSwipeRefreshLayout> {
35+
public class SwipeRefreshLayoutManager extends ViewGroupManager<ReactSwipeRefreshLayout>
36+
implements AndroidSwipeRefreshLayoutManagerInterface<ReactSwipeRefreshLayout> {
3337

3438
public static final String REACT_CLASS = "AndroidSwipeRefreshLayout";
3539

40+
private final ViewManagerDelegate<ReactSwipeRefreshLayout> mDelegate;
41+
42+
public SwipeRefreshLayoutManager() {
43+
mDelegate = new AndroidSwipeRefreshLayoutManagerDelegate<>(this);
44+
}
45+
3646
@Override
3747
protected ReactSwipeRefreshLayout createViewInstance(ThemedReactContext reactContext) {
3848
return new ReactSwipeRefreshLayout(reactContext);
@@ -43,11 +53,13 @@ public String getName() {
4353
return REACT_CLASS;
4454
}
4555

56+
@Override
4657
@ReactProp(name = ViewProps.ENABLED, defaultBoolean = true)
4758
public void setEnabled(ReactSwipeRefreshLayout view, boolean enabled) {
4859
view.setEnabled(enabled);
4960
}
5061

62+
@Override
5163
@ReactProp(name = "colors", customType = "ColorArray")
5264
public void setColors(ReactSwipeRefreshLayout view, @Nullable ReadableArray colors) {
5365
if (colors != null) {
@@ -61,9 +73,16 @@ public void setColors(ReactSwipeRefreshLayout view, @Nullable ReadableArray colo
6173
}
6274
}
6375

64-
@ReactProp(name = "progressBackgroundColor", defaultInt = Color.TRANSPARENT, customType = "Color")
65-
public void setProgressBackgroundColor(ReactSwipeRefreshLayout view, int color) {
66-
view.setProgressBackgroundColorSchemeColor(color);
76+
@Override
77+
@ReactProp(name = "progressBackgroundColor", customType = "Color")
78+
public void setProgressBackgroundColor(ReactSwipeRefreshLayout view, Integer color) {
79+
view.setProgressBackgroundColorSchemeColor(color == null ? Color.TRANSPARENT : color);
80+
}
81+
82+
// TODO(T46143833): Remove this method once the 'size' prop has been migrated to String in JS.
83+
@Override
84+
public void setSize(ReactSwipeRefreshLayout view, int value) {
85+
view.setSize(value);
6786
}
6887

6988
// This prop temporarily takes both 0 and 1 as well as 'default' and 'large'.
@@ -90,11 +109,13 @@ public void setSize(ReactSwipeRefreshLayout view, Dynamic size) {
90109
}
91110
}
92111

112+
@Override
93113
@ReactProp(name = "refreshing")
94114
public void setRefreshing(ReactSwipeRefreshLayout view, boolean refreshing) {
95115
view.setRefreshing(refreshing);
96116
}
97117

118+
@Override
98119
@ReactProp(name = "progressViewOffset", defaultFloat = 0)
99120
public void setProgressViewOffset(final ReactSwipeRefreshLayout view, final float offset) {
100121
view.setProgressViewOffset(offset);
@@ -129,4 +150,9 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
129150
.put("topRefresh", MapBuilder.of("registrationName", "onRefresh"))
130151
.build();
131152
}
153+
154+
@Override
155+
protected ViewManagerDelegate<ReactSwipeRefreshLayout> getDelegate() {
156+
return mDelegate;
157+
}
132158
}

0 commit comments

Comments
 (0)