Repository: incubator-weex
Updated Branches:
  refs/heads/0.15-dev 2c435d13f -> 68e694160


* [android] fix invalid init index


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ab75b9e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ab75b9e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ab75b9e2

Branch: refs/heads/0.15-dev
Commit: ab75b9e262e8da6816c1c47be7dece8d35d22d55
Parents: 7d1602b
Author: misakuo <misa...@apache.org>
Authored: Wed Jul 12 14:43:05 2017 +0800
Committer: misakuo <misa...@apache.org>
Committed: Wed Jul 12 14:43:05 2017 +0800

----------------------------------------------------------------------
 .../com/taobao/weex/ICreateFinishListener.java  | 27 ++++++++++++++++++++
 .../java/com/taobao/weex/WXSDKInstance.java     | 20 +++++++++++++++
 .../com/taobao/weex/ui/component/WXSlider.java  | 17 ++++++++++++
 3 files changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ab75b9e2/android/sdk/src/main/java/com/taobao/weex/ICreateFinishListener.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ICreateFinishListener.java 
b/android/sdk/src/main/java/com/taobao/weex/ICreateFinishListener.java
new file mode 100644
index 0000000..b06fd86
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/ICreateFinishListener.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.taobao.weex;
+
+/**
+ * Created by moxun on 2017/7/12.
+ */
+
+public interface ICreateFinishListener {
+  void onCreateFinish();
+}

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ab75b9e2/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java 
b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
index a8d8a60..9586993 100644
--- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
+++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
@@ -115,6 +115,7 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
   private boolean mNeedValidate = false;
   private static volatile int mViewPortWidth = 750;
   private int mInstanceViewPortWidth = 750;
+  private List<ICreateFinishListener> mCreateFinishListeners;
 
   /**
    * Render strategy.
@@ -995,6 +996,12 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
               WXLogUtils.d(WXLogUtils.WEEX_PERF_TAG, 
mWXPerformance.toString());
             }
           }
+
+          if (mCreateFinishListeners != null) {
+            for (ICreateFinishListener listener : mCreateFinishListeners) {
+              listener.onCreateFinish();
+            }
+          }
         }
       });
     }
@@ -1590,4 +1597,17 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
   public interface NestedInstanceInterceptor {
     void onCreateNestInstance(WXSDKInstance instance, NestedContainer 
container);
   }
+
+  public void addCreateFinishListener(ICreateFinishListener listener) {
+    if (mCreateFinishListeners == null) {
+      mCreateFinishListeners = new ArrayList<>();
+    }
+    mCreateFinishListeners.add(listener);
+  }
+
+  public void removeCreateFinishListener(ICreateFinishListener listener) {
+    if (mCreateFinishListeners != null && listener != null) {
+      mCreateFinishListeners.remove(listener);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ab75b9e2/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
index f436dd0..8fbd291 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
@@ -30,6 +30,7 @@ import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.widget.FrameLayout;
 
+import com.taobao.weex.ICreateFinishListener;
 import com.taobao.weex.WXEnvironment;
 import com.taobao.weex.WXSDKInstance;
 import com.taobao.weex.WXSDKManager;
@@ -62,6 +63,7 @@ public class WXSlider extends WXVContainer<FrameLayout> {
 
   Map<String, Object> params = new HashMap<>();
   private float offsetXAccuracy = 0.1f;
+  private int initIndex = -1;
 
   public static class Creator implements ComponentCreator {
     public WXComponent createInstance(WXSDKInstance instance, WXDomObject 
node, WXVContainer parent) throws IllegalAccessException, 
InvocationTargetException, InstantiationException {
@@ -340,6 +342,7 @@ public class WXSlider extends WXVContainer<FrameLayout> {
   public void setIndex(int index) {
     if (mViewPager != null && mAdapter != null) {
       if (index >= mAdapter.getRealCount() || index < 0) {
+        initIndex = index;
         return;
       }
       mViewPager.setCurrentItem(index);
@@ -509,6 +512,20 @@ public class WXSlider extends WXVContainer<FrameLayout> {
     }
   }
 
+  @Override
+  protected void onHostViewInitialized(FrameLayout host) {
+    super.onHostViewInitialized(host);
+    getInstance().addCreateFinishListener(new ICreateFinishListener() {
+      @Override
+      public void onCreateFinish() {
+        if (mViewPager != null && initIndex != -1) {
+          mViewPager.setCurrentItem(initIndex);
+          initIndex = -1;
+        }
+      }
+    });
+  }
+
   private static class FlingGestureListener extends 
GestureDetector.SimpleOnGestureListener {
     private static final int SWIPE_MIN_DISTANCE = WXViewUtils.dip2px(50);
     private static final int SWIPE_MAX_OFF_PATH = WXViewUtils.dip2px(250);

Reply via email to