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 / Model-View-Presenter Communication.kt
Last active April 8, 2019 12:18
Examples of tests for: 1) testing MVP architecture (Model-View-Presenter Communication.kt) - tests communication between view and presenter and mocking repository behavior; 2) Repository (Repository.kt) - tests how data from local data source and remote data source is received and processed; 3) UI (UI (Integration).kt) - tests UI behavior
//imports are missing
class CardsListPresenterTest {
private lateinit var presenter: CardsListPresenter
private val view = mock<CardsListContact.View>()
private val repository = mock<Repository>()
private val scheduleProvider = ImmediateSchedulerProvider()
// ... some other tests
@Test
@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 / AddEditCardContract.kt
Created July 19, 2018 14:57
Contract (interface) which declare action of Presenter and MVP View. In this case AddEditCardFragment will implement AddEditCardContract.View interface and AddEditCardPresenter will implement AddEditCardContract.Presenter interface
interface AddEditCardContract {
interface Presenter : BasePresenter {
fun getCreditCardLogo(creditCardNumber: String)
fun validateCreditCardNumber(creditCardNumber: String)
fun validateCreditCardHolder(creditCardHolder: String)
fun validateCreditCardExpiryDate(creditExpiryDate: String)
fun validateCreditCardCVV(creditCVV: String)
fun validateCreditCardTypeAndPriority(creditCardType: String, creditCardPriority: String)
fun saveCreditCard(number: String,
holderName: String,
@CyxouD
CyxouD / AddEditCardContract.kt
Last active April 8, 2019 11:58
Model-View-Presenter+Repository architecture example
//contract which declare action of Presenter and MVP View
interface AddEditCardContract {
interface Presenter : BasePresenter {
fun getCreditCardLogo(creditCardNumber: String)
fun validateCreditCardNumber(creditCardNumber: String)
fun validateCreditCardHolder(creditCardHolder: String)
fun validateCreditCardExpiryDate(creditExpiryDate: String)
fun validateCreditCardCVV(creditCVV: String)
fun validateCreditCardTypeAndPriority(creditCardType: String, creditCardPriority: String)
fun saveCreditCard(number: String,
@CyxouD
CyxouD / AddEditCardFragment.kt
Created July 19, 2018 14:59
Fragment which is MVP View which can show credit card logo, show that there is no credit card logo, show credit card number was validated successfully etc (everything defined in AddEditCardContract.kt)
//MVP View
class AddEditCardFragment : BaseFragment<AddEditCardContract.Presenter>(), AddEditCardContract.View {
// ...Android lifecycle methods
override fun setPresenter(presenter: AddEditCardContract.Presenter) {
mPresenter = presenter
}
override fun showCreditCardLogo(creditCardEnum: CreditCardEnum) {
@CyxouD
CyxouD / AddEditCardPresenter.kt
Created July 19, 2018 15:01
Organize between with View (view: AddEditCardContract.View) and Model (repository: DataSource). Performs logic which is not View-dependant and process data from Model before passing it to View
class AddEditCardPresenter(override val repository: DataSource,
val view: AddEditCardContract.View,
override val schedulerProvider: BaseSchedulerProvider,
override val mCompositeDisposable: CompositeDisposable = CompositeDisposable()) : AddEditCardContract.Presenter {
init {
view.setPresenter(this)
}
override fun subscribe() {
}
@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) {