Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion src/utils/filter-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,69 @@

import { StyleSheet } from "react-native";

const isNumber = value => Number.isFinite(value);
const isString = value => Number.isNaN(value);

const validateStyles = {
fontSize: [value => Number.isFinite(value)]
// VIEW - styles
backfaceVisibility: [value => ["visible", "hidden"].includes(value)],
borderColor: [isString],
borderTopColor: [isString],
borderRightColor: [isString],
borderBottomColor: [isString],
borderLeftColor: [isString],
borderWidth: [isNumber],
borderTopWidth: [isNumber],
borderRightWidth: [isNumber],
borderBottomWidth: [isNumber],
borderLeftWidth: [isNumber],
borderRadius: [isNumber],
borderStyle: [value => ["solid", "dotted", "dashed"].includes(value)],
// TEXT - styles
// fontFamily - can't prevent crash, since fonts are loaded dynamically
fontSize: [isNumber],
fontStyle: [value => ["normal", "italic"].includes(value)],
fontVariant: [
value =>
[
"small-caps",
"oldstyle-nums",
"lining-nums",
"tabular-nums",
"proportional-nums"
].includes(value)
],
fontWeight: [
value =>
[
"normal",
"bold",
"100",
"200",
"300",
"400",
"500",
"600",
"700",
"800",
"900"
].includes(value)
],
letterSpacing: [isNumber],
lineHeight: [isNumber],
opacity: [isNumber],
textAlign: [
value => ["auto", "left", "right", "center", "justify"].includes(value)
],
textDecorationLine: [
value =>
["none", "underline", "line-through", "underline line-through"].includes(
value
)
],
textDecorationStyle: [
value => ["solid", "double", "dotted", "dashed"].includes(value)
]
};

const isValidStyle = (style, value) => {
Expand Down