Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement full screen and keep screen awake native functions #190

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions App/screens/onboarding/IntroScreen/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Image } from 'react-native';
import { NativeModules, Platform, Image } from 'react-native';
import { Text } from 'react-native-elements';
import { connect } from 'react-redux';
import { connect as connectNavigation } from '../../../../navigation';
Expand All @@ -11,7 +11,16 @@ import Button from '../../../components/Button';
import VerticalPadding from '../../../components/VerticalPadding';
import Row from '../../../components/Row';

class BaseIntro extends Component {
const ViewUtil = NativeModules.ViewUtil;

class BaseIntro extends Component {
componentDidMount() {
if (Platform.OS != 'ios') {
ViewUtil.keepScreenAwake();
ViewUtil.enterFullScreen();
};
}

static get propTypes() {
return {
navigation: navigationProp.isRequired
Expand Down
6 changes: 5 additions & 1 deletion android/app/src/main/java/io/mobidex/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bitgo.randombytes.RandomBytesPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.horcrux.svg.SvgPackage;
import com.idehub.GoogleAnalyticsBridge.GoogleAnalyticsBridgePackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
Expand All @@ -12,6 +13,7 @@
import com.ocetnik.timer.BackgroundTimerPackage;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import io.mobidex.ViewUtilPackage;
import com.reactnativenavigation.react.ReactGateway;

import java.util.Arrays;
Expand All @@ -35,10 +37,11 @@ protected String getJSMainModuleName() {
public boolean isDebug() {
return BuildConfig.DEBUG;
}

@Override
public List<ReactPackage> createAdditionalReactPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeExceptionHandlerPackage(),
new ReactNativeRestartPackage(),
new RNDeviceInfo(),
Expand All @@ -48,6 +51,7 @@ public List<ReactPackage> createAdditionalReactPackages() {
new VectorIconsPackage(),
new RandomBytesPackage(),
new BackgroundTimerPackage(),
new ViewUtilPackage(),
new RNUUIDGeneratorPackage()
);
}
Expand Down
93 changes: 93 additions & 0 deletions android/app/src/main/java/io/mobidex/ViewUtilModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.mobidex;

import android.app.Activity;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class ViewUtilModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private final Handler uiHandler;
private final Runnable enableImmersive;
private final Runnable disableImmersive;

public ViewUtilModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;

uiHandler = new Handler(reactContext.getMainLooper());
enableImmersive = new Runnable() {
@Override
public void run() {
Activity activity = getCurrentActivity();
if(activity != null && Build.VERSION.SDK_INT >= 14){
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
};

disableImmersive = new Runnable(){
@Override
public void run() {
Activity activity = getCurrentActivity();
if(activity != null && Build.VERSION.SDK_INT >= 14){
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
}
};
}

@Override
public String getName() {
return "ViewUtil";
}

@ReactMethod
public void enterFullScreen(){
uiHandler.post(enableImmersive);
}

@ReactMethod
public void disableFullScreen(){
uiHandler.post(disableImmersive);
}

@ReactMethod
public void keepScreenAwake() {
getCurrentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getCurrentActivity().getWindow()
.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}

@ReactMethod
public void removeScreenAwake() {
getCurrentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getCurrentActivity().getWindow()
.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
}
28 changes: 28 additions & 0 deletions android/app/src/main/java/io/mobidex/ViewUtilPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.mobidex;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ViewUtilPackage implements ReactPackage {

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new ViewUtilModule(reactContext));

return modules;
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}