我正在尝试使用 ReactJS 和 TailwindCSS 创建一个设计系统。
我创建了一个Button具有基本样式的默认组件,如下所示:
import React from "react";
import classNames from "classnames";
const Button = React.forwardRef(
({ children, className = "", onClick }, ref) => {
const buttonClasses = classNames(
className,
"w-24 py-3 bg-red-500 text-white font-bold rounded-full"
);
const commonProps = {
className: buttonClasses,
onClick,
ref
};
return React.createElement(
"button",
{ ...commonProps, type: "button" },
children
);
}
);
export default Button;
Run Code Online (Sandbox Code Playgroud)
然后我在我的页面中使用Button:
import Button from "../src/components/Button";
export default function IndexPage() {
return ( …Run Code Online (Sandbox Code Playgroud) 我正在使用 AWS Amplify 库https://github.com/aws-amplify/amplify-swift与 Cognito 服务进行通信。大多数函数已使用新的 async/await 方法重写。
看下面的方法:
func fetchAuthSession() async throws -> AuthSession {
return try await Amplify.Auth.fetchAuthSession()
}
Run Code Online (Sandbox Code Playgroud)
Observable<AuthSession>如何使用 RxSwift包装等待调用以返回?
我一直在寻找一种在结构中具有通用属性的方法,其中类型在运行时定义,例如:
struct Dog {
let id: String
let value: ??
}
Run Code Online (Sandbox Code Playgroud)
一个有用的简单用例是构建对象时json。Anode可以是int、string、bool、数组等,但除了类型可以改变之外,对象node保持不变。
经过一番思考并使用失败protocols(出现常见protocol 'X' can only be used as a generic constraint because it has Self or associated type requirements错误)后,我想出了两种不同的解决方案,#0 使用type erasure和 #1 使用type-erasureand generics。
#0(类型擦除)
struct AnyDog: Encodable {
enum ValueType: Encodable {
case int(Int)
case string(String)
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch …Run Code Online (Sandbox Code Playgroud) 我目前正在使用Nextjs和使用Expressjs的 api实现身份验证流程。
我希望将 a 存储JWT token为身份验证令牌in memory,我可以使用存储在HTTPOnly cookie.
对于我的实现,我在这里参考了不错的 OSS 项目。
我的问题是,当我inMemoryToken在登录期间存储身份验证令牌时,该值仅存储在可用的客户端但仍然可用的服务器端,反之亦然。
另一个例子是当我断开连接时:
inMemoryToken 等于服务器端的东西logout()称为前端和inMemoryToken = nullgetServerSideProps()在服务器inMemoryToken上调用,但在服务器上仍然等于以前的值,因此我的用户仍然显示为已连接。这是Nextjs代码
//auth.js
import { Component } from 'react';
import Router from 'next/router';
import { serialize } from 'cookie';
import { logout as fetchLogout, refreshToken } from '../services/api';
let inMemoryToken;
export const login = ({ accessToken, accessTokenExpiry }, redirect) …Run Code Online (Sandbox Code Playgroud) 我在使用 NextJS api 转发时遇到了一些问题multipart/form-data。
async function proxy(req: NextApiRequest, res: NextApiResponse): Promise<void> {
const { body, headers, method, url } = req;
// Doing some work to handle authentication
const rewriteUrl = url?.replace('/api/proxy', '');
const config: AxiosRequestConfig = {
url: rewriteUrl,
method: method as Method,
headers: {
cookie: '',
Authorization: token,
},
data: body,
};
try {
const { data: originalData, status } = await axiosInstance(config);
return res.status(status).json(originalData);
} catch (err) {
return res.status(err.status).json(err);
}
}
export default proxy; …Run Code Online (Sandbox Code Playgroud) 我目前正在UICollectionView用几个部分(假设是4个)实现一个,如下图所示:
从第0节到第2 UICollectionViewFlowLayout节,每个节的单元格大小都不同,但是对于第3节,这是自定义布局(瀑布布局)。
我已经实现了2种不同的布局,它们可以在单独的环境中很好地工作UICollectionView,但是我在同一个2种布局之间切换时遇到了一些麻烦UICollectionView。
首先,可以将布局从一个部分更改为另一个部分,如果这样的话,可以实现这一点。
在我的应用程序中,我想更改行高,我使用此字符串扩展名:
extension String {
func addLineHeightWith(alignement: NSTextAlignment) -> NSAttributedString {
let attrString = NSMutableAttributedString(string: self)
let style = NSMutableParagraphStyle()
style.lineSpacing = 5
style.minimumLineHeight = 5
style.alignment = alignement
attrString.addAttribute(NSAttributedStringKey.paragraphStyle, value: style, range: NSRange(location: 0, length: self.count))
return attrString
}
}
Run Code Online (Sandbox Code Playgroud)
我想在UILabel中应用它:
let str = "Hi%5E%5E%F0%9F%98%AC%F0%9F%98%AC%F0%9F%98%AC%F0%9F%98%AC%F0%9F%98%AC%F0%9F%98%AC%F0%9F%98%AC"
if let decoded = str.removingPercentEncoding {
print(decoded)
label.attributedText = decoded.addLineHeightWith(alignement: .center)
}
Run Code Online (Sandbox Code Playgroud)
这是控制台中的结果:
并在屏幕上显示结果:
任何的想法?谢谢
我正在尝试使用SnapKit实现2个视图的动画。
这是我的动画视图:
class MatchAnimation: UIView {
let viewBackground: UIView = {
let view = UIView()
view.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 0.75)
view.alpha = 1
return view
}()
let matchView: UIView = {
let view = UIView()
return view
}()
let matchLabel: UILabel = {
let label = UILabel()
label.text = "Title"
label.textColor = .white
label.textAlignment = .center
return label
}()
let leftAvatarBg: UIView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 91/2
return …Run Code Online (Sandbox Code Playgroud) 我有以下数据:
women_height <- c(105,110,112,112,118,119,120,120,125,126,
127,128,130,132,133,134,135,138,138,138,
138,142,145,148,148,150,151,154,154,158)
Run Code Online (Sandbox Code Playgroud)
以下间隔:
]104;114];]114;124];]124;134];]134;144];]144;154];]154;164];]164;174];]174;184]
Run Code Online (Sandbox Code Playgroud)
我怎样才能发现每个间隔之间有多少女性身高?举个例子 :
] 104; 114] - > 4场比赛
] 114; 124] ---> 4场比赛
...
我在 Swift 中制作了一个应用程序,当您点击按钮时,它可以录制语音。
我想知道需要实现哪个动作来记录,如下例所示:
有没有按钮@IBAction可以做到这一点?
swift ×6
ios ×4
javascript ×3
next.js ×2
reactjs ×2
animation ×1
async-await ×1
cookies ×1
css ×1
encodable ×1
express ×1
generics ×1
intervals ×1
proxy ×1
r ×1
rx-swift ×1
snapkit ×1
statistics ×1
string ×1
struct ×1
tailwind-css ×1
type-erasure ×1