|
1 | 1 | import React, { useContext, useRef, useState } from 'react'
|
2 |
| -import { |
3 |
| - StyleSheet, |
4 |
| - Modal, |
5 |
| - Platform, |
6 |
| - PlatformAndroidStatic, |
7 |
| - KeyboardAvoidingView, |
8 |
| - View |
9 |
| -} from 'react-native' |
| 2 | +import { StyleSheet, Modal, Platform, View } from 'react-native' |
| 3 | +import Ionicons from 'react-native-vector-icons/Ionicons' |
10 | 4 | import { WebView, WebViewNavigation } from 'react-native-webview'
|
11 | 5 |
|
12 | 6 | import useDarkMode from '../../context/useDarkMode'
|
@@ -131,57 +125,49 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
|
131 | 125 | const uri = loginUrl
|
132 | 126 | .replace('{CLIENT_ID}', config.clientId)
|
133 | 127 | .replace('{SCOPE}', encodeURIComponent(config.scope))
|
| 128 | + // Turns out WebView modals are broken on more than Pixel, so we have a full-screen view now. |
134 | 129 | return (
|
135 | 130 | <Modal
|
136 | 131 | animationType='fade'
|
137 | 132 | transparent
|
138 | 133 | visible
|
139 |
| - statusBarTranslucent |
| 134 | + statusBarTranslucent={false} |
140 | 135 | onRequestClose={onRequestClose}
|
141 | 136 | >
|
142 |
| - <KeyboardAvoidingView |
143 |
| - enabled |
144 |
| - behavior='padding' |
145 |
| - style={styles.modalView} |
146 |
| - // https://stackoverflow.com/a/60254214 |
147 |
| - onStartShouldSetResponder={event => { |
148 |
| - const { constants } = Platform as PlatformAndroidStatic |
149 |
| - return ( |
150 |
| - event.nativeEvent.touches.length === 1 && |
151 |
| - // FIXME: Don't handle touch events for Google Pixel devices. |
152 |
| - constants.Manufacturer !== 'Google' && |
153 |
| - constants.Brand !== 'google' |
154 |
| - ) |
155 |
| - }} |
156 |
| - onResponderRelease={event => { |
157 |
| - if (event.target === event.currentTarget) onRequestClose() |
158 |
| - }} |
159 |
| - > |
160 |
| - <View style={styles.webViewContainer}> |
161 |
| - <WebView |
162 |
| - incognito |
163 |
| - ref={webview} |
164 |
| - originWhitelist={['*']} |
165 |
| - source={html ? { html } : { uri }} |
166 |
| - onNavigationStateChange={ev => { |
167 |
| - handleNavigationStateChange(ev).catch(console.error) |
168 |
| - }} |
169 |
| - /> |
| 137 | + <View style={styles.modalView}> |
| 138 | + <View |
| 139 | + style={[ |
| 140 | + darkMode ? styles.modalTopBarDarkBg : styles.modalTopBarLightBg, |
| 141 | + styles.modalTopBar |
| 142 | + ]} |
| 143 | + > |
| 144 | + <Ionicons.Button name='close' onPress={onRequestClose}> |
| 145 | + Close |
| 146 | + </Ionicons.Button> |
170 | 147 | </View>
|
171 |
| - </KeyboardAvoidingView> |
| 148 | + <WebView |
| 149 | + incognito |
| 150 | + ref={webview} |
| 151 | + originWhitelist={['*']} |
| 152 | + source={html ? { html } : { uri }} |
| 153 | + onNavigationStateChange={ev => { |
| 154 | + handleNavigationStateChange(ev).catch(console.error) |
| 155 | + }} |
| 156 | + /> |
| 157 | + </View> |
172 | 158 | </Modal>
|
173 | 159 | )
|
174 | 160 | }
|
175 | 161 |
|
176 | 162 | const styles = StyleSheet.create({
|
177 | 163 | modalView: {
|
178 | 164 | flex: 1,
|
179 |
| - alignItems: 'center', |
180 |
| - justifyContent: 'center', |
181 | 165 | height: '100%',
|
182 |
| - backgroundColor: 'rgba(0, 0, 0, 0.6)' |
| 166 | + width: '100%' |
183 | 167 | },
|
184 |
| - webViewContainer: { height: '80%', width: '80%' } |
| 168 | + modalTopBarLightBg: { backgroundColor: '#ffffff' }, |
| 169 | + modalTopBarDarkBg: { backgroundColor: '#242424' }, |
| 170 | + modalTopBar: { padding: 8, flexDirection: 'row' } |
185 | 171 | })
|
186 | 172 |
|
187 | 173 | export default MicrosoftLogin
|
0 commit comments