Android: implements navbar set center
This commit is contained in:
parent
d8649ac539
commit
007786f4ef
@ -15,14 +15,13 @@
|
||||
*/
|
||||
package pub.doric.navbar;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -34,10 +33,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import com.qmuiteam.qmui.util.QMUIDeviceHelper;
|
||||
import com.qmuiteam.qmui.util.QMUINotchHelper;
|
||||
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
|
||||
|
||||
import pub.doric.R;
|
||||
@ -131,6 +127,15 @@ public class BaseDoricNavBar extends FrameLayout implements IDoricNavBar {
|
||||
mRightContainer.addView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCenter(View view) {
|
||||
mTitleContainer.removeAllViews();
|
||||
mTitleContainer.addView(view);
|
||||
FrameLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams();
|
||||
lp.gravity = Gravity.CENTER;
|
||||
view.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
private void updateTitleMargins() {
|
||||
try {
|
||||
int width = mRightContainer.getRight() - mLeftContainer.getLeft();
|
||||
|
@ -34,4 +34,6 @@ public interface IDoricNavBar {
|
||||
void setLeft(View view);
|
||||
|
||||
void setRight(View view);
|
||||
|
||||
void setCenter(View view);
|
||||
}
|
||||
|
@ -15,12 +15,8 @@
|
||||
*/
|
||||
package pub.doric.plugin;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
@ -47,6 +43,7 @@ public class NavBarPlugin extends DoricJavaPlugin {
|
||||
|
||||
private static final String TYPE_LEFT = "navbar_left";
|
||||
private static final String TYPE_RIGHT = "navbar_right";
|
||||
private static final String TYPE_CENTER = "navbar_center";
|
||||
|
||||
public NavBarPlugin(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
@ -201,4 +198,47 @@ public class NavBarPlugin extends DoricJavaPlugin {
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void setCenter(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
final JSObject jsObject = decoder.decode().asObject();
|
||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
String viewId = jsObject.getProperty("id").asString().value();
|
||||
String type = jsObject.getProperty("type").asString().value();
|
||||
ViewNode node = ViewNode.create(getDoricContext(), type);
|
||||
node.setId(viewId);
|
||||
node.init(new FrameLayout.LayoutParams(0, 0));
|
||||
node.blend(jsObject.getProperty("props").asObject());
|
||||
|
||||
getDoricContext().getDoricNavBar().setCenter(node.getNodeView());
|
||||
|
||||
getDoricContext().clearHeadNodes(TYPE_CENTER);
|
||||
getDoricContext().addHeadNode(TYPE_CENTER, node);
|
||||
return null;
|
||||
}
|
||||
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {
|
||||
@Override
|
||||
public void onResult(Object result) {
|
||||
promise.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
promise.reject(new JavaValue(t.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user