Skip to content

Instantly share code, notes, and snippets.

@gajjartejas
Last active August 10, 2019 06:37
Show Gist options
  • Save gajjartejas/f0b78580c47913de626f907804b01720 to your computer and use it in GitHub Desktop.
Save gajjartejas/f0b78580c47913de626f907804b01720 to your computer and use it in GitHub Desktop.

1. To install lint use:

yarn add --dev eslint babel-eslint eslint eslint-plugin-react eslint-plugin-react-native
yarn add --dev eslint @react-native-community/eslint-config

2. Keyboard dismiss after changing TextInput on Android:

For android keyboard open close issue

blurOnSubmit={false}

3. For android keyboard open even on activity close issue:

Add

returnKeyType={"next”}

and not implement

onSubmitEditing={() => { this.email.focus(); }}

4. To disable accessibility feature on components add on app.js

if (Text.defaultProps == null) Text.defaultProps = {};
Text.defaultProps.allowFontScaling = false;

if (TextInput.defaultProps == null) TextInput.defaultProps = {};
TextInput.defaultProps.allowFontScaling = false;

if (Button.defaultProps == null) Button.defaultProps = {};
Button.defaultProps.allowFontScaling = false;

5. Missing Compliance

Unless your app is using some special encryption you can simply add Boolean a key to your Info.plist with name ITSAppUsesNonExemptEncryption and value NO.

<key>ITSAppUsesNonExemptEncryption</key>
<false/>

6. Create Simulator build:

xcodebuild -workspace <*ProjectName*>.xcworkspace -scheme <*SchemeName*>  -arch x86_64 -sdk iphonesimulator<Version>

7. Send apns using pem file:

curl -v -d '{"aps":{"alert":"hello"}}' -H "apns-topic: BUNDEL_ID"  --http2  --cert PEM_FILE_PATH :PASSWORD  https://api.push.apple.com/3/device/DEVICE_TOKEN

8. Bundle android:

mkdir -p android/app/src/main/assets && rm -rf android/app/build && react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

9. Responsiveness Screen

import { Dimensions, Platform, PixelRatio } from 'react-native';

export const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get(
  'window',
);

// based on iphone X's scale
const wscale = SCREEN_WIDTH / 375;
const hscale = SCREEN_HEIGHT / 812;

export function normalize(size, based = 'width') {
  const newSize = based === 'height' ? size * hscale : size * wscale;
  if (Platform.OS === 'ios') {
    return Math.round(PixelRatio.roundToNearestPixel(newSize));
  } else {
    return Math.round(PixelRatio.roundToNearestPixel(newSize)) - 2;
  }
}

uses

// import { useScreens } from 'react-native-screens';
// useScreens();
// iphone X
normalize(100) // = 100

// iphone 5s
normalize(100) // = maybe 80

// You can choose either "width" (default) or "height" depend on cases:
container = {
  width: normalize(100, "width"), // "width" is optional, it's default
  height: normalize(100, "height")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment