fix android & iOS consistency

This commit is contained in:
王劲鹏 2020-01-14 17:10:40 +08:00 committed by osborn
parent 7f20103148
commit 12bfb16ea1
3 changed files with 17 additions and 7 deletions

View File

@ -15,10 +15,7 @@
*/
package pub.doric;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@ -41,9 +38,5 @@ public class DoricActivity extends AppCompatActivity {
.add(R.id.container, doricFragment)
.commit();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}

View File

@ -15,8 +15,12 @@
*/
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;
@ -68,6 +72,16 @@ public class NavBarPlugin extends DoricJavaPlugin {
JSObject jsObject = jsDecoder.decode().asObject();
boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
navBar.setHidden(hidden);
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (hidden) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
promise.resolve();
} catch (ArchiveException e) {
e.printStackTrace();

View File

@ -16,6 +16,7 @@ import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode;
@DoricPlugin(name = "statusbar")
@ -38,8 +39,10 @@ public class StatusBarPlugin extends DoricJavaPlugin {
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext());
View decorView = activity.getWindow().getDecorView();
if (hidden) {
decorView.setPadding(0, DoricUtils.getStatusBarHeight(activity), 0, 0);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
} else {
decorView.setPadding(0, 0, 0, 0);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
currentMode = 0;