verdnatura-chat/app/share.js

136 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-07-18 17:44:02 +00:00
import React from 'react';
import { View } from 'react-native';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
2019-12-04 16:39:53 +00:00
import { AppearanceProvider } from 'react-native-appearance';
import { createStackNavigator } from 'react-navigation-stack';
2019-07-18 17:44:02 +00:00
import { Provider } from 'react-redux';
2019-07-29 16:33:28 +00:00
import RNUserDefaults from 'rn-user-defaults';
2019-07-18 17:44:02 +00:00
2019-12-04 16:39:53 +00:00
import {
defaultTheme,
newThemeState,
subscribeTheme,
unsubscribeTheme
} from './utils/theme';
2019-07-29 16:33:28 +00:00
import Navigation from './lib/ShareNavigation';
2019-07-18 17:44:02 +00:00
import store from './lib/createStore';
import sharedStyles from './views/Styles';
import { hasNotch, supportSystemTheme } from './utils/deviceInfo';
2019-12-04 16:39:53 +00:00
import { defaultHeader, onNavigationStateChange, cardStyle } from './utils/navigation';
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
import { ThemeContext } from './theme';
[NEW] Passcode and biometric unlock (#2059) * Update expo libs * Configure expo-local-authentication * ScreenLockedView * Authenticate server change * Auth on app resume * localAuthentication util * Add servers.lastLocalAuthenticatedSession column * Save last session date on background * Use our own version of app state redux * Fix libs * Remove inactive * ScreenLockConfigView * Apply on saved data * Auto lock option label * Starting passcode * Basic passcode flow working * Change passcode * Check if biometry is enrolled * Use fork * Migration * Patch expo-local-authentication * Use async storage * Styling * Timer * Refactor * Lock orientation portrait when not on tablet * share extension * Deep linking * Share extension * Refactoring passcode * use state * Stash * Refactor * Change passcode * Animate dots on error * Matching passcodes * Shake * Remove lib * Delete button * Fade animation on modal * Refactoring * ItemInfo * I18n * I18n * Remove unnecessary prop * Save biometry column * Raise time to lock to 30 seconds * Vibrate on wrong confirmation passcode * Reset attempts and save last authentication on local passcode confirmation * Remove inline style * Save last auth * Fix header blink * Change function name * Fix android modal * Fix vibration permission * PasscodeEnter calls biometry * Passcode on the state * Biometry button on PasscodeEnter * Show whole passcode * Secure passcode * Save passcode with promise to prevent empty passcodes and immediately lock * Patch expo-local-authentication * I18n * Fix biometry being called every time * Blur screen on app inactive * Revert "Blur screen on app inactive" This reverts commit a4ce812934adcf6cf87eb1a92aec9283e2f26753. * Remove immediately because of how Activities work on Android * Pods * New layout * stash * Layout refactored * Fix icons * Force set passcode from server * Lint * Improve permission message * Forced passcode subtitle * Disable based on admin's choice * Require local authentication on login success * Refactor * Update tests * Update react-native-device-info to fix notch * Lint * Fix modal * Fix icons * Fix min auto lock time * Review * keep enabled on mobile * fix forced by admin when enable unlock with passcode * use DEFAULT_AUTO_LOCK when manual enable screenLock * fix check has passcode * request biometry on first password * reset auto time lock when disabled on server Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
2020-05-08 17:04:37 +00:00
import { localAuthenticate } from './utils/localAuthentication';
import ScreenLockedView from './views/ScreenLockedView';
2019-07-18 17:44:02 +00:00
const InsideNavigator = createStackNavigator({
2019-07-29 16:33:28 +00:00
ShareListView: {
getScreen: () => require('./views/ShareListView').default
},
ShareView: {
getScreen: () => require('./views/ShareView').default
},
SelectServerView: {
getScreen: () => require('./views/SelectServerView').default
}
2019-07-18 17:44:02 +00:00
}, {
initialRouteName: 'ShareListView',
2019-12-04 16:39:53 +00:00
defaultNavigationOptions: defaultHeader,
cardStyle
2019-07-18 17:44:02 +00:00
});
const OutsideNavigator = createStackNavigator({
2019-07-29 16:33:28 +00:00
WithoutServersView: {
getScreen: () => require('./views/WithoutServersView').default
}
2019-07-18 17:44:02 +00:00
}, {
initialRouteName: 'WithoutServersView',
2019-12-04 16:39:53 +00:00
defaultNavigationOptions: defaultHeader,
cardStyle
2019-07-18 17:44:02 +00:00
});
const AppContainer = createAppContainer(createSwitchNavigator({
OutsideStack: OutsideNavigator,
InsideStack: InsideNavigator,
2019-07-29 16:33:28 +00:00
AuthLoading: {
getScreen: () => require('./views/AuthLoadingView').default
}
2019-07-18 17:44:02 +00:00
},
{
initialRouteName: 'AuthLoading'
}));
class Root extends React.Component {
constructor(props) {
super(props);
this.state = {
2019-12-04 16:39:53 +00:00
isLandscape: false,
theme: defaultTheme(),
themePreferences: {
currentTheme: supportSystemTheme() ? 'automatic' : 'light',
darkLevel: 'dark'
}
};
2019-07-29 16:33:28 +00:00
this.init();
}
2019-12-04 16:39:53 +00:00
componentWillUnmount() {
RocketChat.closeShareExtension();
2019-12-04 16:39:53 +00:00
unsubscribeTheme();
}
2019-07-29 16:33:28 +00:00
init = async() => {
2019-12-04 16:39:53 +00:00
RNUserDefaults.objectForKey(THEME_PREFERENCES_KEY).then(this.setTheme);
2019-07-29 16:33:28 +00:00
const currentServer = await RNUserDefaults.get('currentServer');
const token = await RNUserDefaults.get(RocketChat.TOKEN_KEY);
if (currentServer && token) {
[NEW] Passcode and biometric unlock (#2059) * Update expo libs * Configure expo-local-authentication * ScreenLockedView * Authenticate server change * Auth on app resume * localAuthentication util * Add servers.lastLocalAuthenticatedSession column * Save last session date on background * Use our own version of app state redux * Fix libs * Remove inactive * ScreenLockConfigView * Apply on saved data * Auto lock option label * Starting passcode * Basic passcode flow working * Change passcode * Check if biometry is enrolled * Use fork * Migration * Patch expo-local-authentication * Use async storage * Styling * Timer * Refactor * Lock orientation portrait when not on tablet * share extension * Deep linking * Share extension * Refactoring passcode * use state * Stash * Refactor * Change passcode * Animate dots on error * Matching passcodes * Shake * Remove lib * Delete button * Fade animation on modal * Refactoring * ItemInfo * I18n * I18n * Remove unnecessary prop * Save biometry column * Raise time to lock to 30 seconds * Vibrate on wrong confirmation passcode * Reset attempts and save last authentication on local passcode confirmation * Remove inline style * Save last auth * Fix header blink * Change function name * Fix android modal * Fix vibration permission * PasscodeEnter calls biometry * Passcode on the state * Biometry button on PasscodeEnter * Show whole passcode * Secure passcode * Save passcode with promise to prevent empty passcodes and immediately lock * Patch expo-local-authentication * I18n * Fix biometry being called every time * Blur screen on app inactive * Revert "Blur screen on app inactive" This reverts commit a4ce812934adcf6cf87eb1a92aec9283e2f26753. * Remove immediately because of how Activities work on Android * Pods * New layout * stash * Layout refactored * Fix icons * Force set passcode from server * Lint * Improve permission message * Forced passcode subtitle * Disable based on admin's choice * Require local authentication on login success * Refactor * Update tests * Update react-native-device-info to fix notch * Lint * Fix modal * Fix icons * Fix min auto lock time * Review * keep enabled on mobile * fix forced by admin when enable unlock with passcode * use DEFAULT_AUTO_LOCK when manual enable screenLock * fix check has passcode * request biometry on first password * reset auto time lock when disabled on server Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
2020-05-08 17:04:37 +00:00
await localAuthenticate(currentServer);
2019-07-29 16:33:28 +00:00
await Navigation.navigate('InsideStack');
await RocketChat.shareExtensionInit(currentServer);
} else {
await Navigation.navigate('OutsideStack');
}
2019-07-18 17:44:02 +00:00
}
2019-12-04 16:39:53 +00:00
setTheme = (newTheme = {}) => {
// change theme state
this.setState(prevState => newThemeState(prevState, newTheme), () => {
const { themePreferences } = this.state;
// subscribe to Appearance changes
subscribeTheme(themePreferences, this.setTheme);
});
}
handleLayout = (event) => {
const { width, height } = event.nativeEvent.layout;
this.setState({ isLandscape: width > height });
}
2019-07-18 17:44:02 +00:00
render() {
2019-12-04 16:39:53 +00:00
const { isLandscape, theme } = this.state;
2019-07-18 17:44:02 +00:00
return (
2019-12-04 16:39:53 +00:00
<AppearanceProvider>
<View
style={[sharedStyles.container, isLandscape && hasNotch ? sharedStyles.notchLandscapeContainer : {}]}
2019-12-04 16:39:53 +00:00
onLayout={this.handleLayout}
>
<Provider store={store}>
<ThemeContext.Provider value={{ theme }}>
<AppContainer
ref={(navigatorRef) => {
Navigation.setTopLevelNavigator(navigatorRef);
}}
onNavigationStateChange={onNavigationStateChange}
screenProps={{ theme }}
/>
[NEW] Passcode and biometric unlock (#2059) * Update expo libs * Configure expo-local-authentication * ScreenLockedView * Authenticate server change * Auth on app resume * localAuthentication util * Add servers.lastLocalAuthenticatedSession column * Save last session date on background * Use our own version of app state redux * Fix libs * Remove inactive * ScreenLockConfigView * Apply on saved data * Auto lock option label * Starting passcode * Basic passcode flow working * Change passcode * Check if biometry is enrolled * Use fork * Migration * Patch expo-local-authentication * Use async storage * Styling * Timer * Refactor * Lock orientation portrait when not on tablet * share extension * Deep linking * Share extension * Refactoring passcode * use state * Stash * Refactor * Change passcode * Animate dots on error * Matching passcodes * Shake * Remove lib * Delete button * Fade animation on modal * Refactoring * ItemInfo * I18n * I18n * Remove unnecessary prop * Save biometry column * Raise time to lock to 30 seconds * Vibrate on wrong confirmation passcode * Reset attempts and save last authentication on local passcode confirmation * Remove inline style * Save last auth * Fix header blink * Change function name * Fix android modal * Fix vibration permission * PasscodeEnter calls biometry * Passcode on the state * Biometry button on PasscodeEnter * Show whole passcode * Secure passcode * Save passcode with promise to prevent empty passcodes and immediately lock * Patch expo-local-authentication * I18n * Fix biometry being called every time * Blur screen on app inactive * Revert "Blur screen on app inactive" This reverts commit a4ce812934adcf6cf87eb1a92aec9283e2f26753. * Remove immediately because of how Activities work on Android * Pods * New layout * stash * Layout refactored * Fix icons * Force set passcode from server * Lint * Improve permission message * Forced passcode subtitle * Disable based on admin's choice * Require local authentication on login success * Refactor * Update tests * Update react-native-device-info to fix notch * Lint * Fix modal * Fix icons * Fix min auto lock time * Review * keep enabled on mobile * fix forced by admin when enable unlock with passcode * use DEFAULT_AUTO_LOCK when manual enable screenLock * fix check has passcode * request biometry on first password * reset auto time lock when disabled on server Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
2020-05-08 17:04:37 +00:00
<ScreenLockedView />
2019-12-04 16:39:53 +00:00
</ThemeContext.Provider>
</Provider>
</View>
</AppearanceProvider>
2019-07-18 17:44:02 +00:00
);
}
}
export default Root;