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
import {Field} from "formik"; | |
import {Form} from "whatever-library-you-use"; | |
const FieldInputWrapper = (props) => <Field {...props} as={Form.Input} />; | |
export {FieldInputWrapper} | |
import styled from 'styled-components'; | |
import { FieldInputWrapper } from 'wherever' |
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
import { Form, Formik } from 'formik'; | |
import React from 'react'; | |
export const FormHolder = ({ initialValues, onSubmit, validationSchema, children}) => { | |
return ( | |
<Formik | |
initialValues={initialValues} | |
onSubmit={onSubmit} | |
validationSchema={validationSchema} | |
validateOnChange={false} |
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
import styled from 'styled-components'; | |
const StyledButton = styled(Button)` | |
color: ${({ theme }) => theme.colors.primary}; | |
`; | |
const primary = 'green'; | |
const theme = { | |
colors: { | |
primary, | |
} | |
} |
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
const Title = styled.h1` | |
font-size: 1.5em; | |
text-align: center; | |
color: palevioletred; | |
`; | |
// Create a Wrapper component that'll render a <section> tag with some styles | |
const Wrapper = styled.section` | |
padding: 4em; | |
background: papayawhip; | |
`; |
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
[...] | |
struct ComplicationCorner : View { | |
var entry: QuoteEntry | |
var body: some View { | |
Image(systemName:"quote.bubble") | |
.widgetLabel { | |
Text(entry.quote.quote) | |
.widgetAccentable(true) | |
} | |
.unredacted() |
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
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
var entries: [QuoteEntry] = [] | |
// Generate a timeline consisting of five entries minute apart, starting from the current date. | |
let currentDate = Date() | |
for hourOffset in 0 ..< 5 { | |
let quote = quoteManager.getSingleQuote() | |
let entryDate = Calendar.current.date(byAdding: .minute, value: hourOffset, to: currentDate)! | |
let entry = QuoteEntry(date: entryDate, quote: quote) | |
entries.append(entry) | |
} |
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
struct Provider: TimelineProvider { | |
private let quoteManager = QuoteManager() | |
[...] | |
func getSnapshot(in context: Context, completion: @escaping (QuoteEntry) -> ()) { | |
if context.isPreview { | |
let quote = Quote(quote: "Roses are red", author: "Nobody knows") | |
completion(QuoteEntry(date: Date(), quote: quote)) | |
} else { | |
let quote = quoteManager.getSingleQuote() | |
completion(QuoteEntry(date: Date(), quote: quote)) |
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
@main | |
struct DailyQuote_Complications: Widget { | |
let kind: String = "ro.bartis.DailyQuote.Complications" | |
var body: some WidgetConfiguration { | |
StaticConfiguration(kind: kind, provider: Provider()) { entry in | |
DailyQuote_ComplicationsEntryView(entry: entry) | |
} | |
.configurationDisplayName("Daily Quote") | |
.description("This is a complication that shows you a new quote evey day") | |
} |
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
struct DailyQuote_ComplicationsEntryView : View { | |
@Environment(\.widgetFamily) var widgetFamily | |
var entry: Provider.Entry | |
var body: some View { | |
switch widgetFamily { | |
case .accessoryCorner: | |
ComplicationCorner() | |
case .accessoryCircular: | |
ComplicationCircular() |
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
struct ComplicationInline : View { | |
var body: some View { | |
Text("This will be a quote") | |
.widgetAccentable(true) | |
.unredacted() | |
} | |
} | |
struct ComplicationCircular : View { | |
var body: some View { | |
Text("This will be a quote") |