How do you create and use a custom theme using antd-mobile-rn? - react-native

I want to create and use a custom theme for the antd-mobile-rn library, the Website directs me to: https://github.com/ant-design/antd-mobile-samples/tree/master/rn-custom-ui#antd-mobile-with-rn-custom-ui
I followed the instructions, but he colors remain default. I would prefer not to ass a style to each and every element in my app.
so 2 main questions:
1. how could i debug the script that is called in the package.json "start"
2. has anyone done this and gotten it to work, particularly in react-native

I was able to customize the theme by passing the custom theme file to the ant design "Provider".
You can retrieve the default theme file of antd-mobile-rn here https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx
import {Provider} from '#ant-design/react-native';
import customTheme from './customTheme';
<Provider theme={customTheme}>
<App />
</Provider>
customTheme.tsx file
const brandPrimary = '#42b549';
const brandPrimaryTap = '#5CCF63';
export default {
// 支付宝钱包默认主题
// https://github.com/ant-design/ant-design-mobile/wiki/设计变量表及命名规范
// 色彩, NOTE: must use `#000000` instead of `#000`
// https://facebook.github.io/react-native/docs/colors.html
// 8-digit-hex to 4-digit hex https://css-tricks.com/8-digit-hex-codes/
// https://www.chromestatus.com/feature/5685348285808640 chrome will support `#RGBA`
// 文字色
color_text_base: '#000000', // 基本
color_text_base_inverse: '#ffffff', // 基本 _ 反色
color_text_secondary: '#a4a9b0', // 辅助色
color_text_placeholder: '#bbbbbb', // 文本框提示
color_text_disabled: '#bbbbbb', // 失效
color_text_caption: '#888888', // 辅助描述
color_text_paragraph: '#333333', // 段落
color_link: brandPrimary, // 链接
// 背景色
fill_base: '#ffffff', // 组件默认背景
fill_body: '#f5f5f9', // 页面背景
fill_tap: '#dddddd', // 组件默认背景 _ 按下
fill_disabled: '#dddddd', // 通用失效背景
fill_mask: 'rgba(0, 0, 0, .4)', // 遮罩背景
color_icon_base: '#cccccc', // 许多小图标的背景,比如一些小圆点,加减号
fill_grey: '#f7f7f7',
// 透明度
opacity_disabled: '0.3', // switch checkbox radio 等组件禁用的透明度
// 全局/品牌色
brand_primary: brandPrimary,
brand_primary_tap: brandPrimaryTap,
brand_success: '#6abf47',
brand_warning: '#f4333c',
brand_error: '#f4333c',
brand_important: '#ff5b05', // 用于小红点
brand_wait: '#108ee9',
// 边框色
border_color_base: '#dddddd',
// 字体尺寸
// ---
font_size_icontext: 10,
font_size_caption_sm: 12,
font_size_base: 14,
font_size_subhead: 15,
font_size_caption: 16,
font_size_heading: 17,
// 圆角
// ---
radius_xs: 2,
radius_sm: 3,
radius_md: 5,
radius_lg: 7,
// 边框尺寸
// ---
border_width_sm: 0.5,
border_width_md: 1,
border_width_lg: 2,
// 间距
// ---
// 水平间距
h_spacing_sm: 5,
h_spacing_md: 8,
h_spacing_lg: 15,
// 垂直间距
v_spacing_xs: 3,
v_spacing_sm: 6,
v_spacing_md: 9,
v_spacing_lg: 15,
v_spacing_xl: 21,
// 高度
// ---
line_height_base: 1, // 单行行高
line_height_paragraph: 1.5, // 多行行高
// 图标尺寸
// ---
icon_size_xxs: 15,
icon_size_xs: 18,
icon_size_sm: 21,
icon_size_md: 22, // 导航条上的图标
icon_size_lg: 36,
// 动画缓动
// ---
ease_in_out_quint: 'cubic_bezier(0.86, 0, 0.07, 1)',
// 组件变量
// ---
actionsheet_item_height: 50,
actionsheet_item_font_size: 18,
// button
button_height: 47,
button_font_size: 18,
button_height_sm: 23,
button_font_size_sm: 12,
primary_button_fill: brandPrimary,
primary_button_fill_tap: brandPrimaryTap,
ghost_button_color: brandPrimary, // 同时应用于背景、文字颜色、边框色
ghost_button_fill_tap: `${brandPrimary}99`, // alpha 60% https://codepen.io/chriscoyier/pen/XjbzAW
warning_button_fill: '#e94f4f',
warning_button_fill_tap: '#d24747',
link_button_fill_tap: '#dddddd',
link_button_font_size: 16,
// modal
modal_font_size_heading: 18,
modal_button_font_size: 18, // 按钮字号
modal_button_height: 50, // 按钮高度
// list
list_title_height: 30,
list_item_height_sm: 35,
list_item_height: 44,
// input
input_label_width: 17, // InputItem、TextareaItem 文字长度基础值
input_font_size: 17,
input_color_icon: '#cccccc',
input_color_icon_tap: brandPrimary,
// tabs
tabs_color: brandPrimary,
tabs_height: 42,
tabs_font_size_heading: 15,
// segmented_control
segmented_control_color: brandPrimary, // 同时应用于背景、文字颜色、边框色
segmented_control_height: 27,
segmented_control_fill_tap: `${brandPrimary}10`,
// tab_bar
tab_bar_fill: '#ebeeef',
tab_bar_height: 50,
// toast
toast_fill: 'rgba(0, 0, 0, .8)',
// search_bar
search_bar_fill: '#efeff4',
search_bar_height: 44,
search_bar_input_height: 28,
search_bar_font_size: 15,
search_color_icon: '#bbbbbb', // input search icon 的背景色
// notice_bar
notice_bar_fill: '#fffada',
notice_bar_height: 36,
// switch
switch_fill: '#4dd865',
// tag
tag_height: 25,
tag_small_height: 15,
// picker
option_height: 42, // picker 标题的高度
toast_zindex: 1999,
action_sheet_zindex: 1000,
popup_zindex: 999,
modal_zindex: 999,
};

Related

QMK - RGBLIGHT underglow for ADJUST layer

I have Drop Planck rev. 6 and I managed to get it working almost the way I want. I struggle with the underglow color for ADJUST layer (LWR+RSE). I followed the manual from here: github
The relevant part of my keymap.c looks like this:
const rgblight_segment_t PROGMEM my_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_ORANGE},
{1, 8, HSV_ORANGE}
);
const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_GREEN},
{1, 9, HSV_GREEN}
);
const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_RED},
{1, 8, HSV_RED}
);
const rgblight_segment_t PROGMEM my_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_PURPLE},
{1, 8, HSV_PURPLE}
);
const rgblight_segment_t PROGMEM my_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_CYAN},
{1, 8, HSV_CYAN}
);
const rgblight_segment_t PROGMEM my_layer6_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_BLUE},
{1, 8, HSV_BLUE}
);
const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
my_layer1_layer, // Overrides base layer
my_layer2_layer, // Overrides other layers
my_layer3_layer, // Overrides other layers
my_layer4_layer, // Overrides other layers
my_layer5_layer, // Overrides other layers
my_layer6_layer // Overrides other layers
);
void keyboard_post_init_user(void) {
// Enable the LED layers
rgblight_enable_noeeprom(); // Enables RGB, without saving settings
rgblight_sethsv_noeeprom(HSV_ORANGE);
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
rgblight_layers = my_rgb_layers;
}
layer_state_t default_layer_state_set_user(layer_state_t state) {
rgblight_set_layer_state(0, layer_state_cmp(state, _BASE));
//return state;
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
}
layer_state_t layer_state_set_user(layer_state_t state) {
rgblight_set_layer_state(1, layer_state_cmp(state, _LOWER));
rgblight_set_layer_state(2, layer_state_cmp(state, _RAISE));
rgblight_set_layer_state(3, layer_state_cmp(state, _ADJUST));
rgblight_set_layer_state(4, layer_state_cmp(state, _LAYER4));
rgblight_set_layer_state(5, layer_state_cmp(state, _LAYER5));
//return state;
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
}
LOWER and RAISE layers as well as the other two are backlit as configured, but when I press both LWR and RSE to activate ADJUST layer, the color changes to RED (=RAISE), but the keys are working as expected. When I stop pressing either LWR or RSE, the color then changes to PURPLE (=ADJUST), but the keys are either from RAISE or LOWER respectively.
I am just beginning with QMK with very little knowledge from C, so I think I am missing something trivial and obvious, but cannot find what the issue is caused by.
I would be grateful for anything that would point me to the right direction.
Thanks

Less colors in rgba() even if alpha channel is 1

I need that Less compiler don't convert to HEX colors defined in rgba(), even if alpha channel is 1
Actually, the following Less code:
#color1: rgba(0,0,0,1);
#color2: rgba(0,0,0,0.1);
#color1_light: lighten(#color1,90%);
#color2_light: lighten(#color2,90%);
.a {
background:#color1;
color: #color1_light;
}
.b {
background:#color2;
color: #color2_light;
}
is processed to:
.a {
background: #000000;
color: #e6e6e6;
}
.b {
background: rgba(0, 0, 0, 0.1);
color: rgba(230, 230, 230, 0.1);
}
but I need to have (for many reasons related to further evaluations)
.a {
background: rgba(0, 0, 0, 1);
color: rgba(230, 230, 230, 1);
}
.b {
background: rgba(0, 0, 0, 0.1);
color: rgba(230, 230, 230, 0.1);
}
How to solve this?
Basically this is pretty easy, all you have to do is to escape your expression, below you will find two examples how to force less compiler to display rgba format even though alpha is 1:
#color1: rgba(0,0,0,1);
body {
color: ~"rgba("red(#color1), green(#color1), blue(#color1),~" 1)";
background: %(~"rgba(%s, %s, %s, 1)", red(#color1), green(#color1), blue(#color1));
}
Both examples will produce rgba(0, 0, 0, 1), it's up to you which one do you prefer. I bet you will find more info in the docs under string escape and string replace
//EDIT
yup, this is tricky, but still, you can extend this with a mixin so it won't look that bad in code hereafter.
#color1: rgba(0,0,0,1);
.rgba(#color) {
//#rgba: ~"rgba("red(#color), green(#color), blue(#color),~" 1)";
#rgba: %(~"rgba(%s, %s, %s, %s)", red(#color), green(#color), blue(#color), alpha(#color));
}
.torgba(#property, #color) {
#{property}: %(~"rgba(%s, %s, %s, %s)", red(#color1), green(#color1), blue(#color1), alpha(#color1));
}
body {
.rgba(#color1); // mixin returns #rgba variable that may be used later on, it's not color object however, but a string
color: #rgba;
background: #rgba;
.torgba(border-color, #color1); // do the same, but returns property with color in given format
}

Translate CGBitmapContextCreate from Objective-C to Swift [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
unsigned char pixelData[4] = { 0, 0, 0, 0 };
CGContextRef context = CGBitmapContextCreate(pixelData,
1,
1,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
I want to translate unsigned char pixelData[4] = { 0, 0, 0, 0 }; to Swift. It seems I have to use UnsafeMutableRawPointer. But I do not know how.
You can use a native Swift array and then call its withUnsafeMutableBytes method to get an UnsafeMutableRawBufferPointer to the array's storage. The baseAddress property then gets you the address of the buffer as an UnsafeMutableRawPointer?.
Here's an example:
import CoreGraphics
var pixelData: [UInt8] = [0, 0, 0, 0]
pixelData.withUnsafeMutableBytes { pointer in
guard let colorSpace = CGColorSpace(name: CGColorSpace.displayP3),
let context = CGContext(data: pointer.baseAddress,
width: 1,
height: 1,
bitsPerComponent: 8,
bytesPerRow: 4,
space: colorSpace,
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)
else {
return
}
// Draw a white background
context.setFillColor(CGColor.white)
context.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
}
print(pixelData) // prints [255, 255, 255, 255]
Note that the pointer is only valid inside the closure you pass to withUnsafeMutableBytes. Since the graphics context assumes this pointer is valid for the duration of the context's lifetime, returning the context from the closure and accessing it from the outside would be undefined behavior.
As you can see, however, the contents of the pixelData array have been changed when withUnsafeMutableBytes returns.

How to read R32G32_SFLOAT image from gpu in Vulkan

I am able to dump stuff from R32G32B32A32 image for screenshot. I would like to read out a pixel from R32G32_SFLOAT image as well. But the result look weird.
below is my working image dump code(no validation error)
void DumpImageToFile(VkTool::VulkanDevice &device, VkQueue graphics_queue, VkTool::Wrapper::CommandBuffers &command_buffer, VkImage image, uint32_t width, uint32_t height, const char *filename)
{
auto image_create_info = VkTool::Initializer::GenerateImageCreateInfo(VK_IMAGE_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, {width, height, 1},
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_SAMPLE_COUNT_1_BIT);
VkTool::Wrapper::Image staging_image(device, image_create_info, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
auto buffer_create_info = VkTool::Initializer::GenerateBufferCreateInfo(width * height * 4, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
VkTool::Wrapper::Buffer staging_buffer(device, buffer_create_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
// Copy texture to buffer
command_buffer.Begin();
auto image_memory_barrier = VkTool::Initializer::GenerateImageMemoryBarrier(VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, staging_image.Get());
device.vkCmdPipelineBarrier(command_buffer.Get(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0
, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
image_memory_barrier = VkTool::Initializer::GenerateImageMemoryBarrier(VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, image);
device.vkCmdPipelineBarrier(command_buffer.Get(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0
, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
// Copy!!
VkImageBlit region = {};
region.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
region.srcOffsets[0] = { 0, 0, 0 };
region.srcOffsets[1] = { static_cast<int32_t>(width), static_cast<int32_t>(height), 1};
region.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
region.dstOffsets[0] = { 0, 0, 0 };
region.dstOffsets[1] = { static_cast<int32_t>(width), static_cast<int32_t>(height), 1 };
device.vkCmdBlitImage(command_buffer.Get(), image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, staging_image.Get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region, VK_FILTER_LINEAR);
image_memory_barrier = VkTool::Initializer::GenerateImageMemoryBarrier(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, image);
device.vkCmdPipelineBarrier(command_buffer.Get(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0
, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
image_memory_barrier = VkTool::Initializer::GenerateImageMemoryBarrier(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, staging_image.Get());
device.vkCmdPipelineBarrier(command_buffer.Get(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0
, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
auto buffer_image_copy = VkTool::Initializer::GenerateBufferImageCopy({ VK_IMAGE_ASPECT_COLOR_BIT , 0, 0, 1 }, { width, height, 1 });
device.vkCmdCopyImageToBuffer(command_buffer.Get(), staging_image.Get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, staging_buffer.Get(), 1, &buffer_image_copy);
command_buffer.End();
std::vector<VkCommandBuffer> raw_command_buffers = command_buffer.GetAll();
auto submit_info = VkTool::Initializer::GenerateSubmitInfo(raw_command_buffers);
VkTool::Wrapper::Fence fence(device);
device.vkQueueSubmit(graphics_queue, 1, &submit_info, fence.Get());
fence.Wait();
fence.Destroy();
const uint8_t *mapped_address = reinterpret_cast<const uint8_t *>(staging_buffer.MapMemory());
lodepng::encode(filename, mapped_address, width, height);
staging_buffer.UnmapMemory();
staging_image.Destroy();
staging_buffer.Destroy();
}
Sorry for the ugly self-made wrapper, there was no official wrapper. Basically, it creates a staging image and buffer. first copy from source image to staging image with vkCmdBlitImage. then use vkCmdCopyImageToBuffer and map the buffer to host memory. This method works on multiple gpus and it does not need to worry about padding.(I guess, correct me if I am wrong).
However, I have no luck to use this method to read R32G32_SFLOAT. at first I thought it was because of endianness until I dump the whole image out.
The image above is I directly convert R32G32_SFLOAT to R8G8B8A8_UNORM, I know it does not make sense. But without changing format, there's still a lot of "hole" in the image and values are deadly wrong.
I am not really sure if it is THE problem, but if I understand your code, you want to put image into filename.
So you want to read from this image. However, you said that the old layout for this image (not the staging one) is UNDEFINED layout. The implementation is free to assume you do not care about data that are stored in it. Use the real layout instead (I think it is COLOR_ATTACHMENT or something like that).
Moreover, you are using one staging image and one staging buffer. I do not really understand why are you doing such a thing? Why not simply use vkCmdCopyImageToBuffer function with image to staging_buffer?
BTW, with Vulkan it is not because one code works on some GPUs that this code is correct.
Also, I think you must use a memory barrier after your transfer to the buffer that implies HOST_STAGE and HOST_READ. In the specification, it is write :
Signaling a fence and waiting on the host does not guarantee that the results of memory accesses will be visible to the host, as the access scope of a memory dependency defined by a fence only includes device access. A memory barrier or other memory dependency must be used to guarantee this. See the description of host access types for more information.
This part of your code seems weird:
image_memory_barrier = VkTool::Initializer::GenerateImageMemoryBarrier(VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, image);
device.vkCmdPipelineBarrier(command_buffer.Get(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
This basically means that after the barrier your source image may not have any data. UNDEFINED value used as a source layout doesn't guarantee that the contents of an image are preserved.

Add text to PDF Page using CGPDFContext on OS X

I have tried to add text to an exist PDF file, which has 5 pages, by CGPDF and CGPDFContext but failed. I have set the font, DrawingMode, FillColor... Did I miss something in the code?
CGContextRef writeContext = NULL;
CGRect mediaBox;
CGPDFPageRef page;
size_t i;
page = CGPDFDocumentGetPage(inputDoc, 1);
mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
if (! writeContext)
writeContext = CGPDFContextCreateWithURL(url, &mediaBox, NULL);
CGPDFContextBeginPage(writeContext, NULL);
CGContextDrawPDFPage(writeContext, page);
//Add text
CGContextSelectFont(writeContext, "Helvetic", 26, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(writeContext, kCGTextFill);
CGContextSetRGBFillColor(writeContext, 0, 0, 0, 1);
const char *text="Hello Text Test";
CGContextShowTextAtPoint(writeContext, 100, 100, text, strlen(text));
//=========
CGPDFContextEndPage(writeContext);
}
if (writeContext)
{
CGPDFContextClose(writeContext);
CGContextRelease(writeContext);
}
I found you have a typo in font name Helvetica
CGContextSelectFont(writeContext, "Helvetica", 26, kCGEncodingMacRoman);