From 60be3d27830c6d89da2f4b27c953837253abb385 Mon Sep 17 00:00:00 2001
From: ami9000 <20244930+ami9000@users.noreply.github.com>
Date: Mon, 2 Mar 2020 08:24:09 -0800
Subject: [PATCH] MM-22134: Fix StatusBar after Photo-Camera post in landscape
mode (#3986)
* Fix StatusBar after Photo-Camera post in landscape mode
* revised tests
---
app/components/attachment_button/index.js | 5 ++-
.../attachment_button/index.test.js | 35 +++++++++++++++++--
.../post_textbox/components/camera_button.js | 2 ++
.../components/camera_button.test.js | 20 +++++++++--
.../components/image_upload_button.js | 2 ++
.../components/image_upload_button.test.js | 20 +++++++++--
6 files changed, 74 insertions(+), 10 deletions(-)
diff --git a/app/components/attachment_button/index.js b/app/components/attachment_button/index.js
index 58be8d176..646ed3134 100644
--- a/app/components/attachment_button/index.js
+++ b/app/components/attachment_button/index.js
@@ -8,6 +8,7 @@ import {
NativeModules,
Platform,
StyleSheet,
+ StatusBar,
} from 'react-native';
import RNFetchBlob from 'rn-fetch-blob';
import DeviceInfo from 'react-native-device-info';
@@ -178,6 +179,7 @@ export default class AttachmentButton extends PureComponent {
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
+ StatusBar.setHidden(false);
emmProvider.inBackgroundSince = null;
if (response.error || response.didCancel) {
return;
@@ -213,6 +215,7 @@ export default class AttachmentButton extends PureComponent {
if (hasPhotoPermission) {
ImagePicker.launchImageLibrary(options, (response) => {
+ StatusBar.setHidden(false);
emmProvider.inBackgroundSince = null;
if (response.error || response.didCancel) {
return;
@@ -527,4 +530,4 @@ const style = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
-});
\ No newline at end of file
+});
diff --git a/app/components/attachment_button/index.test.js b/app/components/attachment_button/index.test.js
index cb1d49c68..db9b136af 100644
--- a/app/components/attachment_button/index.test.js
+++ b/app/components/attachment_button/index.test.js
@@ -5,7 +5,7 @@ import React from 'react';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
-import {Alert} from 'react-native';
+import {Alert, StatusBar} from 'react-native';
import Preferences from 'mattermost-redux/constants/preferences';
@@ -15,7 +15,8 @@ import AttachmentButton from './index';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
- launchCamera: jest.fn(),
+ launchCamera: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
+ launchImageLibrary: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('AttachmentButton', () => {
@@ -104,4 +105,32 @@ describe('AttachmentButton', () => {
expect(Alert.alert).toHaveBeenCalled();
expect(hasPhotoPermission).toBe(false);
});
-});
\ No newline at end of file
+
+ test('should re-enable StatusBar after ImagePicker launchCamera finishes', async () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage}}},
+ );
+
+ const instance = wrapper.instance();
+ jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
+ jest.spyOn(StatusBar, 'setHidden');
+
+ await instance.attachFileFromCamera();
+ expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
+ });
+
+ test('should re-enable StatusBar after ImagePicker launchImageLibrary finishes', async () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage}}},
+ );
+
+ const instance = wrapper.instance();
+ jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
+ jest.spyOn(StatusBar, 'setHidden');
+
+ await instance.attachFileFromLibrary();
+ expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
+ });
+});
diff --git a/app/components/post_textbox/components/camera_button.js b/app/components/post_textbox/components/camera_button.js
index e5d24649a..14a744bd9 100644
--- a/app/components/post_textbox/components/camera_button.js
+++ b/app/components/post_textbox/components/camera_button.js
@@ -6,6 +6,7 @@ import {intlShape} from 'react-intl';
import {
Alert,
Platform,
+ StatusBar,
} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import {ICON_SIZE} from 'app/constants/post_textbox';
@@ -93,6 +94,7 @@ export default class AttachmentButton extends PureComponent {
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
+ StatusBar.setHidden(false);
if (response.error || response.didCancel) {
return;
}
diff --git a/app/components/post_textbox/components/camera_button.test.js b/app/components/post_textbox/components/camera_button.test.js
index 1c5f3674d..b6dafee04 100644
--- a/app/components/post_textbox/components/camera_button.test.js
+++ b/app/components/post_textbox/components/camera_button.test.js
@@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
-import {Alert, Platform} from 'react-native';
+import {Alert, Platform, StatusBar} from 'react-native';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
@@ -12,7 +12,7 @@ import CameraButton from './camera_button';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
- launchCamera: jest.fn(),
+ launchCamera: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('CameraButton', () => {
@@ -100,4 +100,18 @@ describe('CameraButton', () => {
expect(hasPermission).toBe(true);
}
});
-});
\ No newline at end of file
+
+ test('should re-enable StatusBar after ImagePicker launchCamera finishes', async () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage}}},
+ );
+
+ const instance = wrapper.instance();
+ jest.spyOn(instance, 'hasCameraPermission').mockReturnValue(true);
+ jest.spyOn(StatusBar, 'setHidden');
+
+ await instance.attachFileFromCamera();
+ expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
+ });
+});
diff --git a/app/components/post_textbox/components/image_upload_button.js b/app/components/post_textbox/components/image_upload_button.js
index 4ecab9468..35feeec75 100644
--- a/app/components/post_textbox/components/image_upload_button.js
+++ b/app/components/post_textbox/components/image_upload_button.js
@@ -6,6 +6,7 @@ import {intlShape} from 'react-intl';
import {
Alert,
Platform,
+ StatusBar,
} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import {ICON_SIZE} from 'app/constants/post_textbox';
@@ -95,6 +96,7 @@ export default class ImageUploadButton extends PureComponent {
if (hasPhotoPermission) {
ImagePicker.launchImageLibrary(options, (response) => {
+ StatusBar.setHidden(false);
if (response.error || response.didCancel) {
return;
}
diff --git a/app/components/post_textbox/components/image_upload_button.test.js b/app/components/post_textbox/components/image_upload_button.test.js
index 20a444cc1..be82b39dc 100644
--- a/app/components/post_textbox/components/image_upload_button.test.js
+++ b/app/components/post_textbox/components/image_upload_button.test.js
@@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
-import {Alert, Platform} from 'react-native';
+import {Alert, Platform, StatusBar} from 'react-native';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
@@ -12,7 +12,7 @@ import ImageUploadButton from './image_upload_button';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
- launchCamera: jest.fn(),
+ launchImageLibrary: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('ImageUploadButton', () => {
@@ -101,4 +101,18 @@ describe('ImageUploadButton', () => {
expect(hasPermission).toBe(true);
}
});
-});
\ No newline at end of file
+
+ test('should re-enable StatusBar after ImagePicker launchImageLibrary finishes', async () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage}}},
+ );
+
+ const instance = wrapper.instance();
+ jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
+ jest.spyOn(StatusBar, 'setHidden');
+
+ await instance.attachFileFromLibrary();
+ expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
+ });
+});