ARKIT issue.
On upgrading the iPhone ios from 15.6 to ios 16, i am facing issue in loading virtual object contents on the screen.
Below mentioned code is working fine with iPhone iOS version 15.6.
In ios 16, below function is keep on calling in the code.
Tag: ProcessRaycastResults
private func setVirtualObject3DPosition(_ results: [ARRaycastResult], with virtualObject: VirtualObject) {
guard let result =
results.first else {
print("Unexpected case: the update handler is always supposed to return at least one result.")
return;
}
self.setTransform(of: virtualObject, with: result)
// If the virtual object is not yet in the scene, add it.
if virtualObject.parent == nil {
self.childNodesPortal = virtualObject.childNodes
self.getMatrials(scene: virtualObject.childNodes)
}
}
func getMatrials(scene:[SCNNode]){
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5 ) {
for child in scene {
material.diffuse.contents = "https//xyz.png"
material.normal.contents = "https//xss.png"
//setting here materials with the png images from url.
}
}
}
Anyone could suggest why there is variation for iOS version 16 device and what workaround I should do.
I've been trying to get a FabricJs canvas work with multitouch pan and zoom, but to no avail. I've tried countless custom builds but the event doesn't have any touch information to work on. Here's the code I use:
let fabricCanvas = new fabric.Canvas('myCanvas', {
width: canvasContainer.current.offsetWidth,
height: canvasContainer.current.offsetHeight,
isDrawingMode: true
})
fabricCanvas.on({
'touch:gesture': function(e) {
console.log(e) // returns empty object wen fired with fabricCanvas.fire("touch:gesture")
}
});
fabricCanvas.fire("touch:gesture") // I can only make the listener fire, by doing this
How can I make the gestures provided work normally?
If you look at the library code, there's a line preventing gesture event being fired when isDrawingMode is true.
in /src/mixins/canvas_gestures.mixin.js
__onTransformGesture: function(e, self) {
if (this.isDrawingMode || !e.touches || e.touches.length !== 2 || 'gesture' !== self.gesture) {
return;
}
var target = this.findTarget(e);
if ('undefined' !== typeof target) {
this.__gesturesParams = {
e: e,
self: self,
target: target
};
this.__gesturesRenderer();
}
this.fire('touch:gesture', {
target: target, e: e, self: self
});
},
I'm also trying to use gesture with drawingMode and don't know why it prevents gesture on drawingMode.
Currently, I'm trying to use a custom build with modified source code.
Or you can try not to use isDrawingMode and use mouse events to implement freedraw
I'm currently working on a react-native app and I'm trying to animate the layout of the login-screen when a keyboard is shown.
To track the state of the keyboard, I'm using this code:
componentDidMount() {
this.keyboardDidShowSub = Keyboard.addListener('keyboardDidShow', (event) => console.log(event));
this.keyboardDidHideSub = Keyboard.addListener('keyboardDidHide', (event) => console.log(event));
}
keyboardDidShow is working and returning:
Object {
"endCoordinates": Object {
"height": 286,
"screenX": 0,
"screenY": 354,
"width": 360,
},
}
However, keyboardDidHide is NOT working and returning null.
What could cause my problem? Thank you so much for your help!!
This is expected behaviour in Android. If you look at the underlying native code that is called when the keyboard is shown/hidden you can see what is sent back to the javascript side.
private void checkForKeyboardEvents() {
getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
final int heightDiff =
DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
// keyboard is now showing, or the keyboard height has changed
mKeyboardHeight = heightDiff;
WritableMap params = Arguments.createMap();
WritableMap coordinates = Arguments.createMap();
coordinates.putDouble("screenY", PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom));
coordinates.putDouble("screenX", PixelUtil.toDIPFromPixel(mVisibleViewArea.left));
coordinates.putDouble("width", PixelUtil.toDIPFromPixel(mVisibleViewArea.width()));
coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
params.putMap("endCoordinates", coordinates);
sendEvent("keyboardDidShow", params);
} else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
// keyboard is now hidden
mKeyboardHeight = 0;
sendEvent("keyboardDidHide", null); // <- you can see here that when the keyboard is hidden it sends back null
}
}
It is worthwhile noting that in iOS that 'keyboardWillShow', 'keyboardDidShow', 'keyboardWillHide' and 'keyboardDidHide' will return an object.
I need a debug output with colorful string, like node.js chalk.
I tried to find the packages, but there is no proper package.
I created the screenshots and code below in VS Code, but supposedly it also works in Android Studio now too:
void main() {
print('This is a normal message.');
printWarning('This is a warning.');
printError('This is an error.');
}
void printWarning(String text) {
print('\x1B[33m$text\x1B[0m');
}
void printError(String text) {
print('\x1B[31m$text\x1B[0m');
}
ANSI escape code explanation
The ANSI escape code string is pretty confusing if you're not familiar with the format.
Here is the string to turn Hello red:
\x1B[31mHello\x1B[0m
And here it is again with spaces added for clarity between the parts:
\x1B [31m Hello \x1B [0m
Meaning:
\x1B: ANSI escape sequence starting marker
[31m: Escape sequence for red
[0m: Escape sequence for reset (stop making the text red)
Here are the other colors:
Black: \x1B[30m
Red: \x1B[31m
Green: \x1B[32m
Yellow: \x1B[33m
Blue: \x1B[34m
Magenta: \x1B[35m
Cyan: \x1B[36m
White: \x1B[37m
Reset: \x1B[0m
Learn more from these links:
Build your own Command Line with ANSI escape codes
ANSI escape code
You need to print escape sequences to get the color effects in terminal output.
See also https://en.wikipedia.org/wiki/ANSI_escape_code
https://pub.dartlang.org/packages/ansicolor is a Dart package that makes this easy.
Emoji
You can use colors for text as others mentioned in their answers to have colorful text with a background or foreground color.
But you can use emojis instead! for example, you can useβ οΈ for warning messages and π for error messages.
Or simply use these notebooks as a color:
π: error message
π: warning message
π: ok status message
π: action message
π: canceled status message
π: Or anything you like and want to recognize immediately by color
π Bonus:
This method also helps you to quickly scan and find logs directly in the source code.
But some distributions of Linuxβs default emoji font is not colorful by default and you may want to make them colorful, first.
How to open emoji panel?
mac os: control + command + space
windows: win + .
linux: control + . or control + ;
I recommend using Grep Console if you don't want to change the way you actually print the characters
You can add a tag like [DEBUG] to your logs and grep console would do the magic for you.
Though text coloring works perfect in terminal it may not work in debug output of IDE (I've tried Idea/Android Studio and VSCode).
Example of ANSI Escape Codes using:
print('\x1B[94m' + "hahAHaHA!!!" + '\x1B[0m');
Examples of using ansicolor package:
import 'package:ansicolor/ansicolor.dart';
main(List<String> arguments) {
AnsiPen greenPen = AnsiPen()..green();
AnsiPen greenBackGroundPen = AnsiPen()..green(bg: true);
AnsiPen redTextBlueBackgroundPen = AnsiPen()..blue(bg: true)..red();
AnsiPen boldPen = AnsiPen()..white(bold: true);
AnsiPen someColorPen = AnsiPen()..rgb(r: .5, g: .2, b: .4);
print(greenPen("Hulk") + " " + greenBackGroundPen("SMASH!!!"));
print(redTextBlueBackgroundPen("Spider-Man!!!") + " " + boldPen("Far From Home!!!"));
print(someColorPen("Chameleon"));
}
PS Came here to find some info on text coloring in terminal, not in debug output of IDE. So I decided to write examples here and do not create separate question with answer.
Styles & Colors in any IDE
There is a package that is just as natural as print(). Simply call printRich()instead.
printRich("This is my String", foreground: Colors.blue, italic: true);
printWarning("This is a very important warning"); //Will be yellow
You can change fore- and background colors and adjust text styles (italic, bold, underline, etc.). This package should work with any IDE as long as it uses ANSI (most IDEs can display this, including Android Studio).
Currently, Dart console does not parse ANSI colors in Android Studio or IntelliJ Idea.
You can check ANSI color support by calling
import dart.io as io
io.stdout.supportsAnsiEscapes
But you can have colorful logs in Android Studio, just open a terminal window in android studio and call
flutter logs
This command attaches the current terminal session to the active flutter session.
Use this terminal for logs. Debug tab, for other functionality.
Preview
I just wanted to share my Logger using the Enhanced Enums.
It works with Flutter 3 and minimum Dart SDK version is 2.17.0.
enum Logger {
Black("30"),
Red("31"),
Green("32"),
Yellow("33"),
Blue("34"),
Magenta("35"),
Cyan("36"),
White("37");
final String code;
const Logger(this.code);
void log(dynamic text) =>
print('\x1B[' + code+ 'm' + text.toString() + '\x1B[0m');
}
Example:
Logger.Green.log("I Love Coffee!");
import 'dart:developer' as developer;
void printW(String text) {
developer.log('\x1B[33m$text\x1B[0m');
}
void printE(String text) {
developer.log('\x1B[31m$text\x1B[0m');
}
void printI(String text) {
developer.log('\x1B[36m$text\x1B[0m');
}
void printS(String text) {
developer.log('\x1B[32m$text\x1B[0m');
}
OUTPUT
USE CASE
prettyPrint(tag: "Profile", value: "200", type: DebugType.statusCode);
prettyPrint(tag: "Profile", value: "Wrong password entered", type: DebugType.error);
prettyPrint(tag: "Profile", value: "google.com", type: DebugType.url);
prettyPrint(tag: "Profile", value: "key_id", type: DebugType.info);
prettyPrint(tag: "Profile", value: "API response", type: DebugType.response);
UTILITY
import 'package:flutter/material.dart';
enum DebugType { error, info, url, response, statusCode }
prettyPrint(
{required String tag,
required dynamic value,
DebugType type = DebugType.info}) {
switch (type) {
case DebugType.statusCode:
{
debugPrint('\x1B[33m${"π STATUS CODE $tag: $value"}\x1B[0m');
break;
}
case DebugType.info:
{
debugPrint('\x1B[32m${"β‘ INFO $tag: $value"}\x1B[0m');
break;
}
case DebugType.error:
{
debugPrint('\x1B[31m${"π¨ ERROR $tag: $value"}\x1B[0m');
break;
}
case DebugType.response:
{
debugPrint('\x1B[36m${"π‘ RESPONSE $tag: $value"}\x1B[0m');
break;
}
case DebugType.url:
{
debugPrint('\x1B[34m${"π URL $tag: $value"}\x1B[0m');
break;
}
}
}
Improved from above code.
import 'package:flutter/foundation.dart';
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
void printDebug(Object? object) {
if (kDebugMode) {
print(object);
}
}
Map<String, Stopwatch> _statusMaps = Map<String, Stopwatch>();
void startTimer(String name) {
if (kDebugMode) {
var _stopwatch = Stopwatch();
_stopwatch.start();
var status = '${name} starting\n';
_statusMaps[name] = _stopwatch;
printCustom("Timer", status);
}
}
void stopTimer(String name) {
if (kDebugMode) {
Stopwatch _stopwatch;
if (_statusMaps.containsKey(name)) {
_stopwatch = _statusMaps[name]!;
var status = '${name} executed in ${_stopwatch.elapsed}';
printCustom("Timer", status);
_statusMaps.remove(name);
}
}
}
printCustom(String name, String status, [String charater = 'β‘']) {
debugPrint('\x1B[33m${"$charater $name: $status"}\x1B[0m');
}
enum DebugType { error, info, url, response, statusCode }
prettyPrint(
{required String tag,
required dynamic value,
DebugType type = DebugType.info}) {
switch (type) {
case DebugType.statusCode:
{
debugPrint('\x1B[33m${"π STATUS CODE $tag: $value"}\x1B[0m');
break;
}
case DebugType.info:
{
debugPrint('\x1B[32m${"β‘ INFO $tag: $value"}\x1B[0m');
break;
}
case DebugType.error:
{
debugPrint('\x1B[31m${"π¨ ERROR $tag: $value"}\x1B[0m');
break;
}
case DebugType.response:
{
debugPrint('\x1B[36m${"π‘ RESPONSE $tag: $value"}\x1B[0m');
break;
}
case DebugType.url:
{
debugPrint('\x1B[34m${"π URL $tag: $value"}\x1B[0m');
break;
}
}
}
I need to be able to set the fontFamily for an entire IText object even if it has character specific styling (code example and jsfiddle below). Note, when changing the fontFamily the character-specific styles don't change. Is there a way for me to access and clear those styles and then apply the style to the entire set of characters?
http://jsfiddle.net/xmfw65qg/48/
var iTextSample = new fabric.IText('hello\nworld', {
styles: {
0: {
0: { textDecoration: 'underline', fontSize: 80 },
1: { textBackgroundColor: 'red' }
},
1: {
0: { textBackgroundColor: 'rgba(0,255,0,0.5)' },
4: { fontSize: 20 }
}
}
});
2020 May Edit
In later revisions of fabricJS, the method removeStyle(props) has been added.
That means you can do:
myTextObject.removeStyle('fontFamily');
to clean it up.
You also have:
myTextObject.cleanStyle('fontFamily');
That will instead remove all the fontaFamily properties that are duplicated of the main object. So that the style object is reduced in complexity if possible.
Original answer
http://jsfiddle.net/asturur/xmfw65qg/50/
you have to manually iterate the style object and clear the fontFamily property.
function setFont(name, value) {
var object = canvas.item(0);
if (!object) return;
if (object.styles) {
var styles = object.styles;
for (var row in styles) {
for (var char in styles[row]) {
if ('fontFamily' in styles[row][char]) {
delete styles[row][char]['fontFamily'];
}
}
}
}
object.set(name, value).setCoords();
canvas.renderAll();
}
why this is necessary is another matter.
I would open an issue on the github repository for that.
Edit:
As fabricjs released 1.6.2 a small bug that was causing the original style object to be changed during rendering, has been fixed.