Skip to content

Instantly share code, notes, and snippets.

View alfian0's full-sized avatar
🎯
Focusing

Muhammad Alfiansyah alfian0

🎯
Focusing
View GitHub Profile
@alfian0
alfian0 / Localization.swift
Created December 11, 2016 15:49
For get Localization String By Language Code
import Foundation
class Localization {
static let instance: Localization = Localization()
func getLocalizationBy(langCode: String, key: String) -> String? {
guard let path = NSBundle.mainBundle().pathForResource(langCode, ofType: "lproj") else { return nil }
let bundle = NSBundle(path: path)
return bundle?.localizedStringForKey(key, value: nil, table: nil)
}
@alfian0
alfian0 / index.ios.js
Created March 2, 2017 09:42
[Redux] React Native - Create Store
import React from 'react';
import {
AppRegistry,
} from 'react-native';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import reducer from './app/reducers';
import AppContainer from './app/containers/AppContainer';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { ActionCreators } from '../actions';
import ApplicationTabs from '../components/ApplicationTabs';
class AppContainer extends Component {
render() {
return (
<ApplicationTabs {...this.props} />
@alfian0
alfian0 / ApiRouter.js
Created March 2, 2017 09:46
[React Native] - Simplify React Native Fetch
class Api {
static headers() {
return {
Accept: 'application/json',
'Content-Type': 'application/json',
dataType: 'json',
};
}
static get(route) {
@alfian0
alfian0 / AxiosRouter.js
Created March 2, 2017 09:47
[Axios] - React Native Networking Module with Axios
import * as axios from 'axios';
const instance = axios.create();
instance.defaults.baseURL = 'http://www.recipepuppy.com';
instance.defaults.headers.common.Accept = 'application/json';
instance.defaults.headers.common['Content-Type'] = 'application/json';
instance.defaults.headers.common.dataType = 'json';
instance.defaults.headers.common.responseType = 'json';
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
@alfian0
alfian0 / CallAPIMiddleware.js
Created March 2, 2017 09:49
[Redux] [React Native] - Networking action wrapper
import makeActionCreator from './makeActionCreator';
export default function callAPIMiddleware({ dispatch, getState }) {
return next => (action) => {
const {
types,
callAPI,
shouldCallAPI = () => true,
payload = {}
} = action;
@alfian0
alfian0 / createReducer.js
Created March 2, 2017 09:51
[Redux][React Native] - Reducer Creator for simplify create reducer
export default function createReducer(initialState, handlers) {
return function reducer(state = initialState, action) {
if (handlers.hasOwnProperty(action.type)) {
return handlers[action.type](state, action);
}
return state;
};
}
@alfian0
alfian0 / makeActionCreator.js
Created March 2, 2017 09:52
[Redux][React Native] - Simplify redux action creation
export default function makeActionCreator(type, ...argNames) {
return function (...args) {
const action = { type };
argNames.forEach((arg, index) => {
action[argNames[index]] = args[index];
});
return action;
};
}
//
// SRCopyableLabel.swift
//
// Created by Stephen Radford on 08/09/2015.
// Copyright (c) 2015 Cocoon Development Ltd. All rights reserved.
//
import UIKit
class SRCopyableLabel: UILabel {
@alfian0
alfian0 / TabBarController.swift
Created June 3, 2017 14:27
Hide UITabBarController
extension UITabBarController {
func setTabBarVisible(visible:Bool, animated:Bool) {
let frame = self.tabBar.frame
let height = frame.size.height
let offsetY = (visible ? -height : height)
UIView.animate(withDuration: animated ? 0.3 : 0.0) {
self.tabBar.frame = frame.offsetBy(dx: 0, dy: offsetY)
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height + offsetY)