Skip to content

Instantly share code, notes, and snippets.

View CyxouD's full-sized avatar

Dmitriy Zasukha CyxouD

  • Ukraine, Dnipro
View GitHub Profile
import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import { TextInput } from 'react-native';
/*
Combined 2 solutions to achieve purpose of scrolling with custom font on Android and long text not render on iOS:
- https://github.com/facebook/react-native/issues/18132#issuecomment-499267942
- https://github.com/facebook/react-native/issues/19453#issuecomment-481071561
*/
const ScrollWithCustomFontFixedTextInput = props => {
@CyxouD
CyxouD / .eslintrc.json
Last active February 6, 2020 14:34
https://github.com/Stormotion-Mobile typescript eslint json configuration. Steps: 1. Add to root of the project as `.eslintrc.json`; 2. Call `yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-native`
{
"env": {
"browser": true,
"es6": true,
"react-native/react-native": true // In order to whitelist all browser-like globals
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
@CyxouD
CyxouD / BaseCard.tsx
Last active December 26, 2019 15:56
BaseCard component to fix losing background on Android when borderRadius is set, which happens in some cases on React-Native 0.60+ (original issue https://github.com/facebook/react-native/issues/15826). Card, TouchableCard are it's implementations. You can disable this fix for some cases with `fixAndroidBehaviour` prop.
import * as React from 'react';
import { PropsWithChildren } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
const CARD_RADIUS = 16;
const SHADOW = '#0000004D';
export interface FixAndroidBehaviourProp {
// disable it if have issues with rendering without it and already have correct background color under your component
// (fixes this https://github.com/facebook/react-native/issues/15826)
@CyxouD
CyxouD / AddEditCardPresenterTest.kt
Last active April 8, 2019 12:16
Tests to simulate AddEditCardPresenter actions
//... imports
class AddEditCardPresenterTest {
private lateinit var presenter: AddEditCardPresenter
private val view = mock<AddEditCardContract.View>()
private val repository = mock<VoyaRepository>()
private val scheduleProvider = ImmediateSchedulerProvider()
private val creditCardNumbers = mapOf(
CreditCardEnum.AMERICAN_EXPRESS to listOf("371449635398431",
@CyxouD
CyxouD / App.java
Last active November 7, 2018 17:16
enable strict mode
public class MyApplication extends Application {
private static final String TAG = "MyApplication";
@Override
public void onCreate() {
if (BuildConfig.DEBUG) {
Log.w(TAG, "======================================================");
Log.w(TAG, "======= APPLICATION IN STRICT MODE - DEBUGGING =======");
Log.w(TAG, "======================================================");
@CyxouD
CyxouD / gist:7eaf69ccff3c0745c3a32fec4e92c065
Created August 16, 2018 07:07
Make all libraries to use same support libs version (26.1.0 in this case) - place it in your root build.gradle (I placed in build script)
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}
@CyxouD
CyxouD / RetrofitService.kt
Created July 19, 2018 15:09
Interface, which declare PUT, GET, POST etc methods, which Retrofit (Http network client) will use to create network requests
interface RetrofitService {
companion object {
fun create(): DevGetVoilaService {
val clientBuilder = OkHttpClient.Builder().apply {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
addInterceptor(loggingInterceptor)
addInterceptor(AuthenticationInterceptor())
addInterceptor(AuditInterceptor())
}
@CyxouD
CyxouD / Repository.kt
Created July 19, 2018 15:07
This file is responsible for organizing communication between local and remote data sources (storages) and passing result with RxJava Observables
open class Repository private constructor(
remoteDataSource: DataSource,
localDataSource: DataSource)
: DataSource {
private val mRemoteDataSource = remoteDataSource
private val mLocalDataSource = localDataSource
companion object {
private var INSTANCE: Repository? = null
@CyxouD
CyxouD / RemoteDataSource.kt
Created July 19, 2018 15:05
This file is responsible for handling network request using Retrofit and pass result with RxJava Observables
open class RemoteDataSource private constructor() : DataSource {
private val service by lazy {
RetrofitService.create()
}
companion object {
private var INSTANCE: RemoteDataSource? = null
@CyxouD
CyxouD / LocalDataSource.kt
Created July 19, 2018 15:04
This file is responsible for handling of saving data locally in Realm Database, Shared preferences, Android Secure storage, retrieving data and passing it with RxJava Observables
open class LocalDataSource private constructor() : DataSource, AnkoLogger {
private val authorizeTokenAlias = "authorizeTokenAlias"
private val conversationIdAlias = "conversationIdAlias"
companion object {
private var INSTANCE: LocalDataSource? = null
fun getInstance(): LocalDataSource {
if (INSTANCE == null) {