react-native#Platform JavaScript Examples
The following examples show how to use
react-native#Platform.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.css.js From bluezone-app with GNU General Public License v3.0 | 6 votes |
styles = StyleSheet.create({
container: {
height: heightPercentageToDP((50 / 720) * 100),
flexDirection: 'row',
alignItems: 'center',
width: '100%',
},
btnBack: {
position: 'absolute',
left: 0,
top: 0,
bottom: 0,
height: heightPercentageToDP((50 / 720) * 100),
justifyContent: 'center',
zIndex: 99,
},
textTitle: {
fontSize: fontSize.huge,
textAlign: 'center',
color: '#000',
},
icon: {
paddingLeft: 20,
paddingRight: 30,
...Platform.select({
ios: {
paddingTop: 5,
},
}),
},
title: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
})
Example #2
Source File: ReduxNavigation.js From Alfredo-Mobile with MIT License | 6 votes |
componentDidMount () {
if (Platform.OS === 'ios') return
BackHandler.addEventListener('hardwareBackPress', () => {
const { dispatch, nav } = this.props
// change to whatever is your first screen, otherwise unpredictable results may occur
if (nav.routes.length === 1 && (nav.routes[0].routeName === 'LaunchScreen')) {
return false
}
// if (shouldCloseApp(nav)) return false
dispatch({ type: 'Navigation/BACK' })
return true
})
}
Example #3
Source File: App.js From Legacy with Mozilla Public License 2.0 | 6 votes |
function StackNav() {
const loggedIn = useSelector(i => i.loggedIn);
return <Stack.Navigator
screenOptions={({ navigation, route }) => ({
gestureEnabled: Platform.OS == 'ios',
// animationEnabled: false,
header: (props) => <Header {...(props || {})} />,
})}>
{loggedIn && <>
<Stack.Screen
name="_redirect"
component={RedirectScreen}
/>
{screens.filter(i => !i.nologin).map(screen => <Stack.Screen
key={screen.name}
name={screen.name}
component={screen.screen}
/>)}
</>}
<Stack.Screen
name="Auth"
options={{
title: "Authenticate",
}}
component={AuthScreen}
/>
{screens.filter(i => i.nologin).map(screen => <Stack.Screen
key={screen.name}
name={screen.name}
component={screen.screen}
/>)}
</Stack.Navigator>
}
Example #4
Source File: CalendarComponent.js From react-native-todolist with MIT License | 6 votes |
async componentDidMount() {
console.log("componentDidMount....");
if(Platform.OS === 'android') {
this.checkPermission();
this.messageListener();
//this.props.fetchAnnouncement();
}
this.props.fetchPlanners(true)
}
Example #5
Source File: helpers.js From React-Messenger-App with MIT License | 6 votes |
/**
* Create touchable component based on passed parameter and platform.
* It also returns default props for specific touchable types.
*/
export function makeTouchable(TouchableComponent) {
const Touchable = TouchableComponent || Platform.select({
android: TouchableNativeFeedback,
ios: TouchableHighlight,
default: TouchableHighlight,
});
let defaultTouchableProps = {};
if (Touchable === TouchableHighlight) {
defaultTouchableProps = { underlayColor: 'rgba(0, 0, 0, 0.1)' };
}
return { Touchable, defaultTouchableProps };
}
Example #6
Source File: SettingsScreen.js From filen-mobile with GNU Affero General Public License v3.0 | 6 votes |
SettingsButton = memo(({ title, rightComponent }) => {
const [darkMode, setDarkMode] = useMMKVBoolean("darkMode", storage)
return (
<View style={{
width: "100%",
height: "auto"
}}>
<View style={{
width: "100%",
height: "auto",
flexDirection: "row",
justifyContent: "space-between",
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10
}}>
<View>
<Text style={{
color: darkMode ? "white" : "black",
paddingTop: typeof rightComponent !== "undefined" ? (Platform.OS == "android" ? 3 : 7) : 0
}}>
{title}
</Text>
</View>
{
typeof rightComponent !== "undefined" && (
<View>
{rightComponent}
</View>
)
}
</View>
</View>
)
})
Example #7
Source File: react-native.js From fuel-js with Apache License 2.0 | 6 votes |
export function generateSecureRandom(length) {
if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
throw Error('react-native-securerandom is currently only available for iOS and Android');
}
if (!RNSecureRandom || !RNSecureRandom.generateSecureRandomAsBase64) {
throw Error('react-native-securerandom is not properly linked');
}
return RNSecureRandom.generateSecureRandomAsBase64(length).then(base64 => toByteArray(base64));
}
Example #8
Source File: useKeyboardStatus.js From react-native-country-codes-picker with MIT License | 6 votes |
useKeyboardStatus = () => {
const [isOpen, setIsOpen] = useState(false);
const [keyboardHeight, setKeyboardHeight] = useState(0);
const keyboardHideListener = useRef(null);
const keyboardShowListener = useRef(null);
const onKeyboardShow = e => {
setKeyboardHeight(e.endCoordinates.height);
setIsOpen(true);
}
const onKeyboardHide = () => {
setKeyboardHeight(0);
setIsOpen(false);
}
useEffect(() => {
keyboardShowListener.current = Keyboard.addListener('keyboardDidShow', onKeyboardShow);
keyboardHideListener.current = Keyboard.addListener('keyboardDidHide', onKeyboardHide);
return () => {
keyboardShowListener.current.remove();
keyboardHideListener.current.remove();
};
},[]);
return {
isOpen: isOpen,
keyboardHeight: keyboardHeight,
keyboardPlatform: Platform.OS
};
}
Example #9
Source File: InAppReviewWithoutNativeModules-test.js From react-native-in-app-review with MIT License | 6 votes |
describe('test-react-native-in-app-review-without-NativeModules-exist', () => {
it('should throw error in iOS Module if module not exist', async () => {
Platform.OS = 'ios';
const errorMessageExpected =
'InAppReview native module not available, did you forget to link the library?';
expect(() => {
InAppReview.RequestInAppReview();
}).toThrow(errorMessageExpected);
});
it('should throw error in android Module if module not exist', async () => {
Platform.OS = 'android';
const errorMessageExpected =
'InAppReview native module not available, did you forget to link the library?';
expect(() => {
InAppReview.RequestInAppReview();
}).toThrow(errorMessageExpected);
});
it('should throw error in calling in app comment Module if module not exist', async () => {
Platform.OS = 'android';
const errorMessageExpected =
'InAppReview native module not available, did you forget to link the library?';
expect(() => {
InAppReview.requestInAppCommentAppGallery();
}).toThrow(errorMessageExpected);
});
});
Example #10
Source File: OnboardingWrapper.js From haven with MIT License | 6 votes |
async componentWillMount() {
const { setOnboardingStatus } = this.props;
try {
await getConfig();
this.handleServerStarted();
} catch (err) {
if (Platform.OS === 'ios') {
iOSeventEmitter.addListener('onServerStarted', this.handleServerStarted);
} else {
DeviceEventEmitter.addListener('onServerStarted', this.handleServerStarted);
}
setOnboardingStatus('offline');
}
}
Example #11
Source File: requestPermissions.js From covid-alert with Apache License 2.0 | 6 votes |
export async function verifyLocationPermissions() {
console.log('Requesting location permission')
const res = await promiseTimeout(
FIVE_S_IN_MS,
request(
Platform.select({
android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
ios: PERMISSIONS.IOS.LOCATION_ALWAYS
})
)
)
if (res !== RESULTS.GRANTED) {
console.error('Location permission not granted!', { res })
return false
}
return true
}
Example #12
Source File: index.js From guardioes-app with Apache License 2.0 | 6 votes |
styles = StyleSheet.create({
avatar: {
borderColor: '#ffffff',
borderWidth: 3,
},
avatars: {
marginLeft: scale(-20),
borderColor: '#ffffff',
borderWidth: 3,
},
iconStyle: {
marginLeft: scale(5),
},
iconRedeSocial: {
marginBottom: Platform.OS === 'ios' ? -3 : 0,
},
})
Example #13
Source File: PasswordInput.js From RRWallet with MIT License | 6 votes |
render() {
const { length } = this.props;
return (
<TouchableWithoutFeedback onPress={this.onPress}>
<View style={[styles.container, this.props.style]}>
{_.times(length, i => (
<Animatable.View
key={i}
iterationCount="infinite"
transition={"borderColor"}
style={[styles.codeBorder, this.current == i && { borderColor: theme.linkColor }]}>
<Text key={i} style={styles.code}>
{this.inputs[i]}
</Text>
</Animatable.View>
))}
<TextInput
style={styles.textinput}
selectTextOnFocus={false}
ref={this.handleTextRef}
contextMenuHidden={true}
underlineColorAndroid="transparent"
maxLength={this.inputs.length}
keyboardType={Platform.select({ ios: "number-pad", android: "numeric" })}
onChangeText={this.onChangeTextInput}
selectionColor="#DADADA"
autoCorrect={false}></TextInput>
</View>
</TouchableWithoutFeedback>
);
}
Example #14
Source File: bluezone.js From bluezone-app with GNU General Public License v3.0 | 5 votes |
_createAndSendOTPCode = (
PhoneNumber,
TokenFirebase,
success = _defaultFunc,
failure = _defaultFunc,
numberRetry = 0,
) => {
const options = {
method: 'POST',
data: {
PhoneNumber: PhoneNumber,
TokenFirebase: TokenFirebase,
TypeOS: Platform.OS,
},
url: `${DOMAIN}/api/App/CreateAndSendOTPCode`,
timeout: 10000,
};
const _success = response => success(response.data);
axios(options).then(response => {
if (response.status === 200 && response.data.isOk === true) {
_success(response);
return;
}
// Co gang dang ki lai token firebase neu co loi
if (
(response.data.Status ===
CreateAndSendOTPCodeErrorCode.TOKEN_FIREBASE_KHONG_HOP_LE ||
response.data.Status ===
CreateAndSendOTPCodeErrorCode.TOKEN_FIREBASE_CHUA_DANG_KI) &&
numberRetry < 1
) {
numberRetry++;
syncTokenFirebase(
_tokenFirebase => {
_createAndSendOTPCode(
PhoneNumber,
_tokenFirebase,
success, // Cho nay bat buoc la success goc tren param, khong duoc dung _success
failure,
numberRetry,
);
},
() => failure(response), // Sync token firebay loi thi dung luon, day response goc ra
);
} else {
failure(response);
}
}, createErrorFn(failure));
}
Example #15
Source File: CategoryScreen.js From Alfredo-Mobile with MIT License | 5 votes |
OS = Platform.OS