-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: iOS text background padding setting
- Loading branch information
1 parent
4f49f3b
commit 03eb4d1
Showing
17 changed files
with
346 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name-template: 'v$RESOLVED_VERSION 🌈' | ||
tag-template: 'v$RESOLVED_VERSION' | ||
categories: | ||
- title: '🚀 Features' | ||
labels: | ||
- 'feature' | ||
- 'enhancement' | ||
- 'feat' | ||
- title: '🐛 Bug Fixes' | ||
labels: | ||
- 'fix' | ||
- 'bugfix' | ||
- 'bug' | ||
- 'fixed' | ||
- title: '🧰 Maintenance' | ||
labels: | ||
- 'chore' | ||
- 'ci' | ||
- 'refactor' | ||
change-template: '- $TITLE @$AUTHOR (#$NUMBER)' | ||
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. | ||
version-resolver: | ||
major: | ||
labels: | ||
- 'major' | ||
minor: | ||
labels: | ||
- 'minor' | ||
patch: | ||
labels: | ||
- 'patch' | ||
default: patch | ||
template: | | ||
## Changes | ||
$CHANGES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Constants.swift | ||
// react-native-image-marker | ||
// | ||
// Created by Jimmydaddy on 2023/8/10. | ||
// | ||
|
||
enum ErrorDomainEnum: String { | ||
case PARAMS_REQUIRED = "com.jimmydaddy.imagemarker.PARAMS_REQUIRED" | ||
case PARAMS_INVALID = "com.jimmydaddy.imagemarker.PARAMS_INVALID" | ||
case BASE = "com.jimmydaddy.imagemarker" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// | ||
// Padding.swift | ||
// react-native-image-marker | ||
// | ||
// Created by Jimmydaddy on 2023/8/9. | ||
// | ||
|
||
import Foundation | ||
|
||
class Padding { | ||
var paddingTop: String = "0" | ||
var paddingLeft: String = "0" | ||
var paddingBottom: String = "0" | ||
var paddingRight: String = "0" | ||
|
||
init(paddingData: [AnyHashable: Any]) throws { | ||
var topValue: String = "0" | ||
var leftValue: String = "0" | ||
var bottomValue: String = "0" | ||
var rightValue: String = "0" | ||
|
||
for (key, paddingValue) in paddingData { | ||
switch key { | ||
case "padding" as String: | ||
if var paddingValue = paddingValue as? String { | ||
paddingValue = paddingValue.trimmingCharacters(in: .whitespaces) | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 4) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
let values = paddingValue.components(separatedBy: " ") | ||
if values.count == 1 { | ||
topValue = values[0] | ||
leftValue = values[0] | ||
bottomValue = values[0] | ||
rightValue = values[0] | ||
} else if values.count == 2 { | ||
topValue = values[0] | ||
leftValue = values[1] | ||
bottomValue = values[0] | ||
rightValue = values[1] | ||
} else if values.count == 3 { | ||
topValue = values[0] | ||
leftValue = values[1] | ||
bottomValue = values[2] | ||
rightValue = values[1] | ||
} else if values.count == 4 { | ||
topValue = values[0] | ||
leftValue = values[1] | ||
bottomValue = values[2] | ||
rightValue = values[3] | ||
} | ||
break | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
topValue = String(format: "%f", paddingValue) | ||
leftValue = String(format: "%f", paddingValue) | ||
bottomValue = String(format: "%f", paddingValue) | ||
rightValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingLeft" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
leftValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
leftValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingRight" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
rightValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
rightValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingTop" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
topValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
topValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingBottom" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
bottomValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
bottomValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingHorizontal" as String, "paddingX" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
rightValue = paddingValue; | ||
leftValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
leftValue = String(format: "%f", paddingValue) | ||
rightValue = String(format: "%f", paddingValue) | ||
} | ||
case "paddingVertical" as String, "paddingY" as String: | ||
if let paddingValue = paddingValue as? String { | ||
if !Utils.checkSpreadValue(str: paddingValue, maxLength: 1) { | ||
throw NSError(domain: ErrorDomainEnum.PARAMS_INVALID.rawValue, code: 0, userInfo: [NSLocalizedDescriptionKey: "padding is invalid"]) | ||
} | ||
topValue = paddingValue; | ||
bottomValue = paddingValue; | ||
} else if let paddingValue = paddingValue as? CGFloat { | ||
topValue = String(format: "%f", paddingValue) | ||
bottomValue = String(format: "%f", paddingValue) | ||
} | ||
default: | ||
break | ||
} | ||
} | ||
|
||
self.paddingTop = topValue | ||
self.paddingLeft = leftValue | ||
self.paddingBottom = bottomValue | ||
self.paddingRight = rightValue | ||
} | ||
|
||
func toEdgeInsets(width: CGFloat, height: CGFloat) -> UIEdgeInsets { | ||
let topValue = Utils.parseSpreadValue(v: self.paddingTop, relativeTo: height) ?? 0 | ||
let leftValue = Utils.parseSpreadValue(v: self.paddingLeft, relativeTo: width) ?? 0 | ||
let bottomValue = Utils.parseSpreadValue(v: self.paddingBottom, relativeTo: height) ?? 0 | ||
let rightValue = Utils.parseSpreadValue(v: self.paddingRight, relativeTo: width) ?? 0 | ||
return UIEdgeInsets(top: topValue, left: leftValue, bottom: bottomValue, right: rightValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.