added whole content

This commit is contained in:
Fedor Katurov 2022-11-03 10:38:11 +06:00
parent 1b5df685cb
commit 8b25e0631a
70 changed files with 5962 additions and 19 deletions

View file

@ -0,0 +1,48 @@
Use #oauth2 login with React-Native
## Common OAuth2 providers
Can be handled by [react-native-app-auth](react-native-app-auth) by redirecting to url `com.yourapp://oauth2provider`.
### Example for #Google
```typescript
import { authorize } from 'react-native-app-auth';
const GOOGLE_OAUTH_CLIENT = '...';
// ...
const authState = await authorize({
issuer: 'https://accounts.google.com',
clientId: `${GOOGLE_OAUTH_CLIENT}.apps.googleusercontent.com`,
redirectUrl: `com.yourapp:/oauth2redirect/google`,
scopes: ['openid', 'profile'],
dangerouslyAllowInsecureHttpRequests: true,
});
```
### Example for #Yandex
```typescript
const YANDEX_OAUTH_CLIENT = '...';
const YANDEX_OAUTH_SECRET = '...'; // better hide it somehow
const APP_ID = 'com.yourapp';
const authState = await authorize({
serviceConfiguration: {
authorizationEndpoint: `https://oauth.yandex.ru/authorize?response_type=code&client_id=${YANDEX_OAUTH_CLIENT}&redirect_uri=${APP_ID}:/oauth2redirect`,
// TODO: replace it with your own backend to secure client_secret:
tokenEndpoint: `https://oauth.yandex.ru/token?grant_type=authorization_code&client_id=${YANDEX_OAUTH_CLIENT}&client_secret=${YANDEX_OAUTH_SECRET}`,
},
clientId: YANDEX_OAUTH_CLIENT,
redirectUrl: `${APP_ID}:/oauth2redirect`,
scopes: ['login:info', 'login:avatar'],
dangerouslyAllowInsecureHttpRequests: true,
});
callback(authState.accessToken);
```
## Apple ID login
[react-native-apple-authentication](https://github.com/invertase/react-native-apple-authentication) has its own [documentation](https://github.com/invertase/react-native-apple-authentication/tree/main/docs) on setting up OAuth using Apple ID.

View file

@ -0,0 +1,60 @@
Sometimes you need to keep scroll position of `FlatList` in React Native after some user interactions.
```typescript
// interact() is doing some stuff, that changes FlatList scroll size
type Props = { interact: () => void; }
const SomeList: FC<Props> = ({ interact }) => {
const scrollPosition = useRef(0);
const scrollHeight = useRef(0);
// set it to `true` before interaction and back to `false` right after
const shouldKeepScrollPosition = useRef(false);
const onScroll = useCallback(
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
scrollPosition.current = event.nativeEvent.contentOffset.y;
},
[],
);
const onContentSizeChange = useCallback((_: number, h: number) => {
if (!shouldKeepScrollPosition.current) {
scrollHeight.current = h;
return;
}
ref.current?.scrollToOffset({
offset: scrollPosition.current + (h - scrollHeight.current),
animated: false,
});
scrollHeight.current = h;
}, []);
// onInteraction wraps interaction to preserve scroll position
const onInteraction = useCallback(
() => {
shouldKeepScrollPosition.current = true;
setTimeout(() => {
interact();
}, 0);
setTimeout(() => {
shouldKeepScrollPosition.current = false;
}, 500);
},
[setSelectedSubThemes],
);
return (
<FlatList
// ...required FlatList options
ref={ref}
onContentSizeChange={onContentSizeChange}
onRefresh={onRefresh}
onScroll={onScroll}
/>
)
}

View file

@ -0,0 +1,65 @@
## Show android logcat
```shell
adb logcat com.application:I "*:S"
```
## Get .apk's SHA-256
```bash
keytool -printcert -jarfile "$1"
```
## Assemble debug release on Android
Packages release with bundled resources.
```shell
npx 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/
cd android && ./gradlew assembleDebug
# do your stuff
./gradlew clean
```
## Send release to Android device
```shell
cd ./android \
&& ./gradlew assembleRelease \
&& adb install ./app/build/outputs/apk/release/app-release.apk
```
## Deep links
- https://zarah.dev/2022/02/08/android12-deeplinks.html
- https://developer.android.com/training/app-links/verify-site-associations#invoke-domain-verification
- https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://miin.ru&relation=delegate_permission/common.handle_all_urls
### Open deep links
```shell
# ios
xcrun simctl openurl booted $1
# android
adb shell am start -W -a android.intent.action.VIEW -d $1 \
com.application
```
### Reverify links on Android
```shell
PACKAGE="com.application"
adb shell pm set-app-links --package $PACKAGE 0 all && \
adb shell pm verify-app-links --re-verify $PACKAGE
```