This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-03
Channels
- # arachne (1)
- # beginners (75)
- # calva (7)
- # cider (1)
- # clj-kondo (6)
- # cljdoc (3)
- # clojure (74)
- # clojure-brasil (2)
- # clojure-china (6)
- # clojure-italy (16)
- # clojure-nl (1)
- # clojure-spec (23)
- # clojure-uk (5)
- # clojurebridge (1)
- # clojuredesign-podcast (8)
- # clojurescript (4)
- # community-development (1)
- # data-science (1)
- # datavis (1)
- # datomic (5)
- # duct (18)
- # graalvm (2)
- # kaocha (3)
- # onyx (3)
- # other-languages (1)
- # pathom (4)
- # reagent (61)
- # reitit (5)
- # shadow-cljs (8)
- # tools-deps (11)
- # vim (1)
Hey, everybody! I'm stuck in a problem of transfering javascript to clojurescript, and the code following:
javascript
import { createBottomTabNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
....
const TabNavigator = createBottomTabNavigator({
HomeScreen: {
screen: HomeScreen,
navigationOptions:({naviagtion}) => ({
tabBarLabel: 'home',
tabBarIcon: ({focused, tintColor}) => (
<TabBarItem
tintColor={tintColor}
focused={focused}
normalImage={require('./assets/home.png')}
selectedImage={require('./assets/home.png')}
/>
)
})
},
Content: {
screen: content,
navigationOptions:({naviagtion}) => ({
tabBarLabel: 'content',
tabBarIcon: ({focused, tintColor}) => (
<TabBarItem
tintColor={tintColor}
focused={focused}
normalImage={require('./assets/content.png')}
selectedImage={require('./assets/content.png')}
/>
)
})
}
},
{
tabBarOptions: {
activeTintColor: '#4CB4E7',
inactiveTintColor: '#FFEE93',
style: {backgroundColor: '#FFC09F'}
}
});
How can I transfer the code with `navigationOptions` to clojurescript? It'a anonymous function as a `prop`, so maybe some difficult. And this is my effort, but the `tintColor` looks like unuseful.
clojure
(ns react-navigation.core
(:require [goog.object :as gobj]))
(def ReactNavigation (js/require "react-navigation"))
(def create-bottom-tabnavigator (gobj/get ReactNavigation #js ["createBottomTabNavigator"]))
(def create-appcontainer (gobj/get ReactNavigation #js ["createAppContainer"]))
(defn tab-navigator []
(router/create-bottom-tabnavigator
(clj->js {:HomeScreen
(clj->js {:screen (r/reactify-component home-screen)
:navigationOptions (fn [{:keys [navigation]}]
(clj->js {:tabBarLabel "首页"
:tabBarIcon (fn [{:keys [focused, tintColor]}]
(tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/home.png") (js/require "../resources/assets/home.png")))}))})
:Content
(clj->js {:screen (r/reactify-component content/content)
:navigationOptions (fn [{:keys [navigation]}]
(clj->js {:tabBarLabel "内容"
:tabBarIcon (fn [{:keys [focused, tintColor]}]
(tabbar/tab-bar-item tintColor focused (js/require "../resources/assets/content.png") (js/require "../resources/assets/content.png")))}))})})
(clj->js {:tabBarOptions
{:activeTintColor "#4CB4E7"
:inactiveTintColor "#FFEE93"
:style {:backgroundColor "#FFC09F"}}
})))
`Guys, does anyone know how to translate this console.log('\x1b[36m%s\x1b[0m', 'I am cyan')
into ClojureScript
?
What I've tried is (console.log '\x1b[36m%s\x1b[0m', 'I am cyan')
which throws an error regarding the escape sequences.
Solved it: If anyone else is wondering the same, then here's the code
;; Reference:
(def ascii-colors
{:red "\u001b[31m"
:green "\u001b[32m"
:yellow "\u001b[33m"
:blue "\u001b[34m"
:magenta "\u001b[35m"
:cyan "\u001b[36m"
:white "\u001b[37m"
:reset "\u001b[0m"})
(defn colorized-log [color text]
(str ((keyword color) ascii-colors) text (:reset ascii-colors)))
(colorized-log "red" "This is colored!")
Solved it: If anyone else is wondering the same, then here's the code
;; Reference:
(def ascii-colors
{:red "\u001b[31m"
:green "\u001b[32m"
:yellow "\u001b[33m"
:blue "\u001b[34m"
:magenta "\u001b[35m"
:cyan "\u001b[36m"
:white "\u001b[37m"
:reset "\u001b[0m"})
(defn colorized-log [color text]
(str ((keyword color) ascii-colors) text (:reset ascii-colors)))
(colorized-log "red" "This is colored!")