Browse Source

Singleton themes

pull/1/head
Tim Glasgow 2 years ago
parent
commit
a67d5d62b1
  1. 32
      squarenotsquare/src/screens/styles/AppStyles.js
  2. 9
      squarenotsquare/src/themes/Colors.js
  3. 66
      squarenotsquare/src/themes/Fonts.js
  4. 7
      squarenotsquare/src/themes/Icons.js
  5. 40
      squarenotsquare/src/themes/Metrics.js

32
squarenotsquare/src/screens/styles/AppStyles.js

@ -1,7 +1,7 @@
import { StyleSheet } from "react-native"; import { StyleSheet } from "react-native";
import * as colors from '../../themes/Colors'; import Colors from '../../themes/Colors';
import * as fonts from '../../themes/Fonts'; import Fonts from '../../themes/Fonts';
import * as metrics from '../../themes/Metrics'; import Metrics from '../../themes/Metrics';
export const styles = StyleSheet.create({ export const styles = StyleSheet.create({
flex: {flex: 1}, flex: {flex: 1},
@ -28,7 +28,7 @@ export const styles = StyleSheet.create({
stretch: {alignSelf: 'stretch'}, stretch: {alignSelf: 'stretch'},
absolute: { absolute: {
position: 'absolute', position: 'absolute',
top: metrics.screenSections.headerHeight, top: Metrics.screenSections.headerHeight,
bottom: 0, bottom: 0,
left: 0, left: 0,
right: 0, right: 0,
@ -42,24 +42,20 @@ export const styles = StyleSheet.create({
rightText: {textAlign: 'right'}, rightText: {textAlign: 'right'},
leftText: {textAlign: 'left'}, leftText: {textAlign: 'left'},
headerTitleFont: {fontSize: fonts.headerTitle.size}, headerTitleFont: {fontSize: Fonts.headerTitle.size},
largeFont: {fontSize: fonts.large.size}, largeFont: {fontSize: Fonts.large.size},
mediumFont: {fontSize: fonts.medium.size}, mediumFont: {fontSize: Fonts.medium.size},
smallFont: {fontSize: fonts.small.size}, smallFont: {fontSize: Fonts.small.size},
tinyFont: {fontSize: fonts.tiny.size}, tinyFont: {fontSize: Fonts.tiny.size},
subFont: {fontSize: fonts.subFont.size}, subFont: {fontSize: Fonts.subFont.size},
tickFont: {fontSize: fonts.tickFont.size},
italic: {fontStyle: 'italic'}, italic: {fontStyle: 'italic'},
greyText: {color: colors.material.grey600}, greyText: {color: Colors.material.grey600},
redText: {color: colors.material.red800}, redText: {color: Colors.material.red800},
blueText: {color: colors.material.blue400}, blueText: {color: Colors.material.blue400},
boldText: {fontWeight: 'bold'}, boldText: {fontWeight: 'bold'},
lightText: {color: colors.impulseColors.lightText},
darkText: {color: colors.impulseColors.black},
body: { body: {
backgroundColor: colors.material.light, backgroundColor: Colors.material.light,
} }
}) })

9
squarenotsquare/src/themes/Colors.js

@ -1,4 +1,5 @@
export const material = { class AppColors {
material = {
dark: '#212121', dark: '#212121',
light: '#ffffff', light: '#ffffff',
@ -25,7 +26,11 @@ export const material = {
green800: '#2e7d32', green800: '#2e7d32',
} }
export const fonts = { fonts = {
dark: '#000000', dark: '#000000',
light: '#ffffff' light: '#ffffff'
}; };
}
const Colors = new AppColors();
export default Colors;

66
squarenotsquare/src/themes/Fonts.js

@ -1,49 +1,55 @@
import {PixelRatio} from 'react-native'; import {PixelRatio} from 'react-native';
const scalar = PixelRatio.getFontScale(); class AppFonts {
constructor() {
this.scalar = PixelRatio.getFontScale();
function normalizeFont(size) { this.headerTitle = {
return size * scalar
};
export const fonts = {
headerTitle: {
fam: 'arial', fam: 'arial',
size: normalizeFont(30), size: this.normalizeFont(30),
}, }
sectionHeader: { this.sectionHeader = {
fam: 'arial', fam: 'arial',
size: normalizeFont(26), size: this.normalizeFont(26),
}, }
large: { this.large = {
fam: 'arial', fam: 'arial',
size: normalizeFont(22), size: this.normalizeFont(22),
}, }
medium: { this.medium = {
fam: 'arial', fam: 'arial',
size: normalizeFont(20), size: this.normalizeFont(20),
}, }
small: { this.small = {
fam: 'arial', fam: 'arial',
size: normalizeFont(16), size: this.normalizeFont(16),
}, }
tiny: { this.tiny = {
fam: 'arial', fam: 'arial',
size: normalizeFont(14), size: this.normalizeFont(14),
}, }
mini: { this.mini = {
fam: 'arial', fam: 'arial',
size: normalizeFont(10), size: this.normalizeFont(10),
}, }
subFont: { this.subFont = {
fam: 'arial', fam: 'arial',
size: normalizeFont(8), size: this.normalizeFont(8),
},
} }
}
normalizeFont(size) {
let newSize = size * this.scalar;
return newSize;
};
}
const Fonts = new AppFonts();
export default Fonts;

7
squarenotsquare/src/themes/Icons.js

@ -1,5 +1,10 @@
export const squareIcons = { class AppIcons {
squareIcons = {
settings: 'cog-outline', settings: 'cog-outline',
toggleOn: 'toggle-switch-on', toggleOn: 'toggle-switch-on',
toggleOfff: 'toggle-switch-off' toggleOfff: 'toggle-switch-off'
}; };
}
const Icons = new AppIcons();
export default Icons;

40
squarenotsquare/src/themes/Metrics.js

@ -1,25 +1,35 @@
import { PixelRatio, Dimensions } from "react-native"; import { PixelRatio, Dimensions } from "react-native";
let scalar = PixelRatio.get(); class AppMetrics {
constructor(dimensions = Dimensions.get('window')) {
function normalize(size){ this.scalar = PixelRatio.get();
return (size * scalar);
}
let dimensions = Dimensions.get('window');
let height = dimensions.height; let height = dimensions.height;
let width = dimensions.width; let width = dimensions.width;
let screenWidth = width;
let screenHeight = height;
if (width > height) { if (width > height) {
screenHeight = width; this.screenHeight = width;
screenWidth = height; this.screenWidth = height;
} else {
this.screenWidth = width;
this.screenHeight = height;
}
} }
export const screenSections = { normalize(size){
headerHeight: normalize(20), return (size * this.scalar);
sectionWidth: screenWidth }
screenSections = {
headerHeight: this.normalize(20),
sectionWidth: this.screenWidth
}
}
const Metrics = new AppMetrics();
export default Metrics;
export function buildTestMetrics(dimensions){
const Metrics = new AppMetrics(dimensions);
return Metrics;
} }
Loading…
Cancel
Save