Skip to content

Commit

Permalink
修复部分手机默认选中状态错误的问题,修复#27
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpryv010 committed May 26, 2021
1 parent fe95c69 commit f76b0f9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions android/src/main/java/com/zyu/ReactWheelCurvedPickerManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.zyu;

import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.aigestudio.wheelpicker.WheelPicker;
import com.facebook.react.bridge.ReadableArray;
Expand All @@ -24,6 +27,11 @@ public class ReactWheelCurvedPickerManager extends SimpleViewManager<ReactWheelC

private static final int DEFAULT_TEXT_SIZE = 25 * 2;
private static final int DEFAULT_ITEM_SPACE = 14 * 2;
private static Handler mSDKHandler = new Handler(Looper.getMainLooper());

private static void runOnMainThread(Runnable runnable) {
mSDKHandler.postDelayed(runnable, 0);
}

@Override
protected ReactWheelCurvedPicker createViewInstance(ThemedReactContext reactContext) {
Expand Down Expand Up @@ -96,10 +104,16 @@ public void setData(ReactWheelCurvedPicker picker, ReadableArray items) {
}

@ReactProp(name="selectedIndex")
public void setSelectedIndex(ReactWheelCurvedPicker picker, int index) {
public void setSelectedIndex(final ReactWheelCurvedPicker picker, final int index) {
if (picker != null && picker.getState() == WheelPicker.SCROLL_STATE_IDLE) {
picker.setSelectedItemPosition(index);
picker.invalidate();
//必须放在异步,否则不能确保生效https://github.com/AigeStudio/WheelPicker/issues/156
runOnMainThread(new Runnable() {
@Override
public void run() {
picker.setSelectedItemPosition(index);
picker.invalidate();
}
});
}
}

Expand Down

0 comments on commit f76b0f9

Please sign in to comment.